LouisRaverdy
Projects

Philosophers

Threads/mutex concurrency · the classic trap

Philosophers · threads & mutex

Implementation of the classic dining philosophers problem in C with pthreads and mutexes. Each philosopher alternates between eating, sleeping and thinking while sharing forks with their neighbours. The program must respect timing constraints and precisely detect when a philosopher starves.

The subject looks small, but it concentrates many concurrency problems: shared access, lock ordering, deadlock prevention, synchronised logs, time measurement, clean thread shutdown and absence of data races. A solution that works on a simple case can become unstable as soon as timings change.

This project forces the code to be extremely sober and predictable. It is not enough for the program to print the right lines once: it must remain correct under load, with several philosophers, variable durations, no useless busy loop and no stuck lock.

Stack

CMutexGit

Other projects