DP1

Dining Philosoper with Deadlock

Philosopher i:
 
Pickup:
 
P(chpstk[i]);
P(chpstk[(i+1) mod 5);
 
 
 
Putdown:
 
V(chpstk[i]);
V(chpstk[(i+1) mod 5);
 
 
 
Note:   LEFT = i; RIGHT = (i+1) mod 5

 

DP2

Dining Philosopher with no deadlock (but has starvation)

philosopher i:

Pickup: 
P(mutex)
while not(chpstk[LEFT]and chpstk[RIGHT])   
     do begin
        V(mutex);
        P(sleep[i]);
        P(mutex);
     end;
chpstk[LEFT]:=false; chpstk[RIGHT]:=false;
V(mutex);
 
PutDown
P(mutex)
   chpstk[LEFT]:=true;  
   chpstk[RIGHT]:=true;
   V(sleep[(i+4) mod 5]);
   V(sleep[RIGHT]);
V(mutex);