Notes From CS Undergrad Courses FSU
This project is maintained by awa03
/*
Possible Deadlock, not always
*/
// Thread A
P(x);
P(y)
// Thread B
P(y)
P(x);
semaphore chopstick[5] = {1, 1, 1, 1, 1};
lawyer(int j){
while(TRUE){
// attempt to grab sticks
P(chopstick[j]);
P(chopstick[(j + 1) % 5]);
eat();
// release chopstick
V(chopstick[(j + 1) % 5]);
V(chopstick[j]);
}
}