philosophers
The dining philosophers problem solved with threads and mutexes: one
thread per philosopher, one mutex per fork and a separate monitor
thread that detects starvation and counts meals. A consistent global
order for picking up forks rules out deadlock. Sleeps are split into
short slices, because a plain usleep can overshoot by
tens of milliseconds, and with tight parameters that is enough to
kill a philosopher. ThreadSanitizer checks for data races, because a
hundred clean runs prove nothing.