臨界區問題:
假設現有n個進程(P1, P2,…,Pn), 每個進程都如圖所示, 擁有一個可以修改共享變量(變量, 文件, 數據庫表等)的臨界區(critical section), 要求任何一個進程在臨界區執行時, 其他都不能執行.
正式定義:
- Mutual exclusion(互斥): When a thread is executing in its critical section, no other threads can be executing in their critical sections.
- Progress(前進): If no thread is executing in its critical section, and if there are some threads that wish to enter their critical sections, then one of these threads will get into the critical section.
- Bounded waiting(有限次等待): After a thread makes a request to enter its critical section, there is a bound on the number of times that other threads are allowed to enter their critical sections, before the request is granted.