多線程的優點和代價
多線程優點:
https://ifeve.com/benefits/
1. 資源利用率更好
2. 程序設計在某些情況下更簡單
3. 程序響應更快序響應更快
while(server is active){
listen for request
hand request to worker thread
}
多線程的代價:
https://ifeve.com/costs-of-multithreading/
1. 設計更複雜
在多線程訪問共享數據的時候,這部分代碼需要特別的注意。線程之間的交互往往非常複雜。
2. 上下文切換的開銷
context switch
3. 增加資源消耗
需要占用操作係統中一些資源來管理線程
最後更新:2017-08-13 22:21:56