dining philosophers

by lowclouds
See Code Download Embed
This is Dijkstra's first solution to the Dining Philosopher's problem, or a close approximation of it. The core of the problem is that no pair of adjacent philosophers can be eating at the same time, so there must be a deadlock free solution to negotiating for the two available forks (not a part of the original problem.)
 
The core of the solution is that there is a single mutex  (the lock on the table) which allows a philosopher to safely point arrows at his neighbors if it's hungry, and to safely remove incoming arrows when finished eating. A philospher can only eat if there are no incoming arrows (Dijkstra was big on graph theory.) 

This solution uses my HSM blocks for the thinking/hungry/eating statechart, although the isthinking function is in my mind a kludge, because the HSM is blocked while hung on the mutex (hence my aversion to mutexes/semaphores and the like.)

Animation of the forks is left to the viewer. 

Created July 2, 2020

Last updated October 14, 2021

Shared July 2, 2020