philosophers
Coordinate philosophers competing for forks, with protected meal state, a monitor, and a process/semaphore bonus implementation.
C · pthreads · Mutexes
The problem
Coordinate concurrent workers that need two shared resources while detecting starvation and keeping output consistent.
A design decision
Use mutexes around fork access, meal timestamps, output and the end flag. A monitor inspects meal state and stops the run when a philosopher dies or the meal quota is reached.
A debugging edge case
The single-philosopher case cannot obtain two forks. The routine handles it explicitly: take one fork, wait until time to die, then report death. Timing and lock ordering remain important test cases for multiple workers.
A possible next iteration
A useful next iteration would add automated stress runs and race-detector checks across odd and even worker counts.
Explore the implementation
This study describes the source at commit e0133ad. The
edge case is a code walkthrough, not a personal debugging story.