0

So based on the Chandy/Misra section in this Wikipedia article we've got 5 philosophers numbered P1-P5.

Based on this quote:

For every pair of philosophers contending for a resource, create a fork and give it to the philosopher with the lower ID (n for agent Pn). Each fork can either be dirty or clean. Initially, all forks are dirty

When a philosopher with a fork receives a request message, he keeps the fork if it is clean, but gives it up when it is dirty. If he sends the fork over, he cleans the fork before doing so.

So with the knowledge that all forks are initially dirty, regard the following quote and the image underneath it.

For every pair of Swansons, give the fork to the guy with the smaller id.

My question is if P3 now requests a second fork from his neighbor P2, will P2 give up his single fork because it was dirty, even though he just picked it up?

Community
  • 1
  • 1
Omar Sharaki
  • 360
  • 9
  • 34

1 Answers1

0

P3 cannot ask P4 for the fork because he already has the fork (acc. to the image).

The fork P4 is holding can only be shared by P4 and P5 (acc. to the problem, you can only ask your neighbors for the fork, which means P3 can only take the fork between P3 & P2 and the fork between P3 & P4 )
In other words, P4 cannot give P3 the fork which currently lies between P4 and P5

Therefore, P3 will have to wait until P2 gives him the second fork

** EDIT **
Yes P2 will give up the fork since it's dirty

dev_ankit
  • 516
  • 4
  • 8
  • Yes you are right. The question was badly formulated. I changed p4 to p2 in the last section. Does it mean now that p2 will give up his fork, since it's dirty, when p3 requests it? – Omar Sharaki May 20 '15 at 22:48