Friday, September 16, 1993 Handout today: project assignment Reminder: instructor out of town next MTuW but lectures meet as usual ------------------------------------------------------------------------------- Proof of correctness of Peterson's algorithm Mutual exclusion: Assume p1 has just passed test and about to enter critical section. At this point plbusy is true. Can p2 enter its critical section and violate mutual exclusion? p1 has passed test not (p2busy and turn == 2) so by DeMorgans, we know (not p2busy) or (turn != 2) Case 1: p2busy is false hence p2 cannot be currently trying to enter its Critical Section if it tries to enter Critical Section it must first clear the while(p1busy and turn == 1) ; test. p1busy is currently true so p2 must wait Case 2: turn != 2 (in other words, turn == 1) implies that wherever p2 is at this time it will find (p1busy and turn == 1) to be true when it attempts to enter its Critical Section and hence will have to wait. Progress and bounded waiting: process prevented from entering critical section only if stuck in while loop Say p1 is circling in while loop p2 is either (1) not trying to enter the critical section (2) waiting in its own while loop, or (3) repeatedly executing its entire loop very quickly. Case 1: p1 detects that p2busy=false hence enters its own loop Case 2: cannot happen because turn must either be 1 or 2, hence one or the other process is clear to go Case 3: cannot happen because p2 will set turn to 1, permitting p1 to proceed and trapping itsenf in its own loop ------------------------------------------------------------------------------- Next: semaphores Help us generalize critical section problem solutions to more complex problems involving more than just two processes