The implementation of the problem and the proposed conclusion do not coincide due to sleep between the forks.
I'm not sure why Michel Foucault always starts all over again (maybe how thread dispatch works), but everything else is easily explained.
Due to the pause (*) between the main and remote forks, there are two phases:
- Phase 1: grab the fork of the main arm
- Stage 2: grab your fork
After phase 1:
- Fork 0 is in the hand of Michel Foucault or Judith Butler.
- Plug 1 is in the hands of Gilles Deleuze
- Fork 2 is in the hand of Karl Marx
- Fork 3 is in the hands of Emma Goldman
Now note that only Fork 4 is available for capture!
We have two cases in Phase 2:
a) Judith grabbed the plug 0 b) Michelle grabbed the plug 0
Starting from (a):
- All philosophers are blocked except for Emma, โโwho captures Fork 4
- When Emma is done, she releases Fork 3, which Carl immediately captures.
- When Karl finished ...
- Finally, Judith finished, she releases plug 0, and Michelle eats
In case (a), only one philosopher can eat at any given time.
Note. I forced the case by stopping Michel for 150 ms before letting him grab his first fork.
Case (b) is more complicated, because again we have a race, this time between Emma and Michel to grab fork 4. We are gentlemen, so Emma will go first, and the case of Michel who grabbed fork 4 is now called (c) :
- Emma captures Fork 4, now all other philosophers are blocked.
- When Emma finished, she releases the forks 3 and 4, and Michelle and Karl jump on them.
- When Michelle is done, he releases Forks 0 and 4, Judith grabs him immediately ... and starts to wait; now no one cares about Fork 4.
- When Carl is complete, he releases Fork 2, which Gilles immediately captures.
- When Gilles is completed, he releases Fork 1, which Judith immediately captures
- When Judith finished, all 5 ate
We observe very limited concurrency here: first Emma appears, and only when she is finished, we have two parallel threads, one with Michel, and one going to Karl> Gilles> Judith.
Note. I forced the case by stopping Michel for 150 ms before letting him grab his second fork.
Finally, we have case (c):
- Michelle grabs Fork 4, now all other philosophers are blocked.
- When Michelle is done, he releases Fork 4 and 0, which respectively capture Emma and Judith; Judith is still blocked (first sleeping, and then waiting for Fork 1), but Emma begins to eat
- When Emma is finished ...
And here again there is no concurrency.
(*) This is not really guaranteed, but 150 ms for a long time computer, if the machine is not loaded, this will happen.
While the solution proposed in the book really works (there is no deadlock, no matter what the circumstances), it does not show much concurrency, therefore it is more a manifestation of rust than an exhibit of concurrency ... but it is Rust's book, not concurrency alone!
I do not understand why the Michel thread is systematically planned first at the arena; but it can be easily contrasted by making him sleep specifically.