1 P(eu); ne := ne+1; V(eu); 2 P(qu); P(eu); 3 nm := nm+1; 4 ne := ne-1; 5 if ne > 0 --> V(eu) 6 [] ne = 0 --> V(mu) 7 fi; 8 V(qu); 9 P(mu); nm := nm-1; a Critical Section b if nm > 0 --> V(mu) c [] nm = 0 --> V(eu) d fi |
|
Idea: Inner/Outer Gates; black-box = critical section; tiny circles = processes; the black circle just finished the CS.
After understanding the idea, disassociate the diagram from the Udding-alg. The gates do not quite correspond to eu mu, and the blue + red processes do not get counted as ne nm.
P(s) ≡ ‹ await s > 0 → s := s-1 ›
V(s) ≡ ‹ s := s+1 ›
Let CP be the name we give to the collection of processes waiting to do P(s).
Consider the following situation. Suppose s == 0. A process P1 is about to do a V(s). If CP is empty, there is nothing interesting. If CP is non-empty, ...
When s becomes 1, a process from CP completes the P-operation. Which process? Any one? FCFS?
What is the time gap between the completion of V(s) and testing of s > 0?
Can P1 join CP? (Because P has code of the form {... V(s); ...; P(s); ...}
Is this important in the solution above?
What is the semaphore qu doing?
The solutions by Udding and Morris to the starvation-free mutual exclusion problem are reproduced below. Conclude nothing from the code line-up.
Udding's solution | Morris' solution 1 P(eu); ne := ne+1; V(eu); | P(em); ne := ne+1; V(em); 2 P(qu); P(eu); | P(qm); 3 nm := nm+1; | nm := nm+1; 4 ne := ne-1; | P(em); ne := ne-1; 5 if ne > 0 --> V(eu) | if ne > 0 --> V(em);V(qm) 6 [] ne = 0 --> V(mu) | [] ne = 0 --> V(em);V(mm) 7 fi; | fi; 8 V(qu); | 9 P(mu); nm := nm-1; | P(mm); nm := nm-1; a Critical Section; | Critical Section; b if nm > 0 --> V(mu) | if nm > 0 --> V(mm) c [] nm = 0 --> V(eu) | [] nm = 0 --> V(qm) d fi | fi