Competition Among Processes for resources · Deadlock 例如,有两个进程P1、P2,竞争两个资源 R1、R2。假设 上占:P1(R2)andP2(R1) 中:P1(R1)andP2(R2) 结果:P1、P2永久等待(死锁)
Competition Among Processes for resources Starvation(饿死) 例如,有三个进程P1、P2、P3,竞争资源R假设 占:P1(R 中凌:P2(R)andP3(R) 释放:P1(R) 占用:P2(R) 中请:P1(R)andP3(R) 释放:P2(R) 占:P1(R 结果:P3(饿死)
Mutual Exclusion mechanism 互斥机制 entry section critical section exit section (阅读P194,图51
(阅读P194,图5.1)
Cooperation Among processes by sharing (进程间由于共享合作) Writing must be mutually exclusive (对写共享变量必须互斥) Critical sections are used to provide data integrity (确保数据完整性使用临界区) 例如:两个数据保持相等:A=B,初始值相等。 P1:A=A+1; B=B+1; P2:B=22B; A=2*A ·当P1和P2顺序执行,能保证一致。但并发执行,就可 能出现A≠B,因此必须采用临界资源管理才能达到数 据的一致性
Cooperation Among Processes by Communication (进程间由于通信的合作) Because nothing is shared between processes in the act of passing messages Mutual exclusion is not a control requirement for this sort of cooperation Possible to have deadlock Each process waiting for a message from the other process Possible to have starvation Two processes sending message to each other while another process waits for a message