Discussion
Consider the following proposed solution to dining philosopher's problem to avoid deadlock. Consider the binary semaphore lock in initialized to 1.
Philosopher (int i)
{ while (1)
{ think ( );
wait (lock); .............(i)
wait (fork [i]);
wait (fork [(i+1)%5]);
signal (lock); ........ (ii)
eat( );
wait (lock); ............. (iii)
signal (fork [i]);
signal (fork (i + 1) % 5);
signal (lock); ............ (iv)
}Which of the following is correct ?
Answer: B
The correct statement is that removing (iii) and (iv) will not affect the code.
The lock around (i) and (ii) makes picking up both forks a single atomic step: a philosopher cannot hold one fork while waiting for another, so the circular wait that causes deadlock cannot form. Removing (i) and (ii) would allow every philosopher to take the left fork at once and deadlock.
Releasing forks needs no such protection. Signalling a semaphore never blocks, so putting the forks down one after the other cannot cause deadlock, and the lock around (iii) and (iv) is unnecessary. That rules out options A, C and D.
Post your comment
Please log in or register to post a comment.
Examination Categories
- SSC Exams
- Banking Exams
- Teaching Exams
- Civil Services Exams
- Railways Exams
- Engineering Recruitment Exams
- Defence Exams
- State Government Exams
- Police Exams
- Insurance Exams
- Nursing Exams
- Other Government Exams
- NRA CET
- PG Entrance Exams
- Campus Placement
- MBA Entrance Exams
- CUET and UG Entrance
- Judiciary Exams
- Regulatory Body Exams
- Software Development