Deadlock avoidance
可以利用演算法避免deadlock
safe state
a save sequence {P~1~, P~2~, ..., P~n~}
P~i~最多可以請求的資源數 = available resources + resources held by all P~j~ , with j < i
unsafe state
Process Termination
Abort all deadlocked processes
Abort one process at a time until the deadlock cycle is eliminated
每丟棄一個process就要執行一次deadlock-detection演算法
丟棄process需要考慮很多因素,如優先權
Resource Preempt
# Threading Issues
## Implicit Threading
* thread 由 compiler 和 run-time library 建立和管理
* 常見方法
* Thread pools
* OpenMP
* Grand Central Dispatch
* TBB(Threading Building Blocks)
### Thread Pools
* 預先建立一些 thread 等待 work
* 優點
* 預先建立好,速度較快
* 執行 thread 的數量被 pool 的大小限制
### OpenMP
* Provides support for parallel programming in <font color="orange">shared-memory</font> environment
* Can identify parallel regions which can run in parallel
### Grand Central Dispatch
* Apple t