Skip to content

Latest commit

 

History

History
31 lines (16 loc) · 942 Bytes

whenToUseParallel.md

File metadata and controls

31 lines (16 loc) · 942 Bytes

甚麼時候用並行 (Parallel) ?





Linus Torvalds 對並行是這麼評價的:

"Where the hell do you envision that those magical parallel algorithms would be used?"

"The only place where parallelism matters is in graphics or on the server side, where we already largely have it. Pushing it anywhere else is just pointless."


除了在圖形運算與伺服器方面廣泛大量使用,其他地方毫無必要使用多執行緒。這是 Lniux 之父對多執行緒的評價。

多執行緒在編寫以及維護方面比串行邏輯較困難,所以能不要用就不要用,除非遇到特定兩種 case:


  • 圖形運算

  • 伺服器開發


讓多個執行緒有效正確工作是一門藝術,保證 Thread safe,理解 multi-thread 的無序性、可見性,不使用鎖改用 CAS (Compare And Swap) 機制提高性能。這些都是這個筆記的重點研究方向。