Dekker's Algorithm First Attempt Busy Waiting Process is always checking to see if it can enter the critical section Process can do nothing productive until it gets permission to enter its critical section
Dekker's Algorithm First Attempt(第1种尝试) ·图5.2“爱斯基摩人的小屋协议”(P198) 门和小屋很小,每次只能容纳一个人进入, 小屋内有一个标志黑板 ·进程申请进入临界区,必须首先进入小屋并检 查黑板标志是否是它 是,离开小屋,进入临界区,执行完毕,退出临界区, 并返回小屋,修改黑板标志为其他进程 否,反复进入小屋,检查黑板标志,直到标志是它自
是,离开小屋,进入临界区,执行完毕,退出临界区, 并返回小屋,修改黑板标志为其他进程 否,反复进入小屋,检查黑板标志,直到标志是它自 己
小黑版指 示P1可进 Critical chon PO Tum Figure 5.2 An Igloo for Mutual Exclusion
小黑版指 示P1可进
var turn:0.1;{共享的全局变量} PROCESS O PROCESS 1 while turn#o do nothing while turn f l do nothing <critical section>: <critical section> turn: =1 turn: =0: 解析 保证了互斥,但存在问题:进程“忙等”进入临 界区;若黑板标志修改失败,其他进程永久塞
var turn:0..1; {共享的全局变量} PROCESS 0 PROCESS 1 … … while turn≠0 do {nothing}; while turn ≠ 1 do {nothing}; <critical section>; <critical section> turn:=1; turn:=0; … …
Dekkers algorithm ★ Second Attempt(第2种尝试) Each process can examine the others status but cannot alter it When a process wants to enter the critical section, It checks the other processes first If no other process is in the critical section. it sets its status for the critical section