ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > Class(2017-2018-1)ZSTU > student homework directory > 2015329620005李闻岚 >
homework6-deadlock Version 0
👤 Author: by arashi 2017-12-21 13:37:34
The dining-philosophers problem is considered a classic synchronization problem neither because of its practical importance nor because computer scientists dislike philosophers but because it is an example of a large class of concurrency-control problems. It is a simple representation of the need to allocate several resources among several processes in a deadlock-free and starvation-free manner.
One simple solution is to represent each chopstick by executing a wait() operation on that semaphore; she releases her chopsticks by executing the signal() operation on the appropriate semaphores. Thus, the shared data are
Semaphore chopstick[5];
Where all the elements of chopstick are initialized to 1. The structure of philosopher I is like following:
Do{
Wait(chopstick[i]);
Wait(chopstick[(I + 1) % 5]);

//eat
Signal(chopstick[i]);
Signal(chopstick[(I + 1) % 5]);

//think

}while(TRUE);
Although this solution guarantees that no two neighbors are eating simultaneously, it nevertheless must be rejected because it could create a deadlock. Suppose that all five philosophers become hungry simultaneously and each grabs her left chopstick. All the elements of chopstick will now be equal to 0. When each philosopher tries to grab her right chopstick, she will be delayed forever.

Please login to reply. Login

Reversion History

Loading...
No reversions found.