ALL > Computer and Education > courses > university courses > undergraduate courses > Operating System > Class(2017-2018-1)ZSTU > student homework directory > 2015329620048_蔡金宏 >
homework_6_deadlock Version 0
👤 Author: by jarvis 2017-12-28 13:47:01
As the five philosophers proceeded concurrently at exactly one moment each philosopher proceeded to apply for chopsticks and successfully applied to the ith chopsticks (equivalent to five philosophers holding up the chopsticks on his left) followed by them  Have to apply for chopsticks on the right apply for the first i chopsticks.  At this moment every philosopher gets only one chopstick and the other one has to wait indefinitely for deadlock.  Given several options to effectively prevent deadlock we first give two assertions
(1) There are N concurrent processes in the system.  If the provisions of each process need to apply for some of the two types of resources when the system provides N 1 resources of the same type no matter what way to apply for resources will not deadlock.  Analysis N 1 resources are N processes competition we can see from the drawer principle there is at least one process has been more than two similar resources.  This is why the five philosophers in the Philosophical Dining mentioned above would certainly not deadlock when offering six chopsticks.
(2) There are N concurrent processes in the system.  If each process needs to apply for R certain types of resources when the system provides 1 similar resource of K = N * (R-1) no deadlock will definitely occur no matter which way to apply for use.  Analysis In the worst case scenario each process applies for R-1 resources of the same type at which time they all block.  Imagine if the system and then add a similar resource the N process must have a process to get R resources deadlock to lift.
Combined with the above analysis philosophers dining problem can be abstractly described as There are five concurrent processes in the system each process requires the application of two certain types of resources.  If the system provides five such resources the guarantee will not produce deadlock under the premise of allowing up to a number of processes concurrent implementation?  Assuming N processes are allowed R = 2 K = 5 are brought into the above equation with N * (2-1) 1 = 5 so N = 4.  This means that if at any time the system allows a maximum of 4 processes to execute concurrently deadlocks must not occur.

 
Semaphorechopstick 5 = 11111; // represents 5 chopsticks respectively
Semaphorefootman = 4; // initial value of 4 allows up to 4 philosopher processes simultaneously
Philosopher (inti)
{while (true)
     {wait (footman);
     Think ();
     Wait (chopstick i); // Apply left chopstick
     Wait (chopstick (i 1)% 5); // Apply right chopstick
     Eat ();
     Signal (chopstick i); // Release the left chopstick
     Signal (chopstick (i 1)% 5); // Release the right chopstick
     Signal (footman);
    }
}

Please login to reply. Login

Reversion History

Loading...
No reversions found.