Skip to content
← Johan Idler

philosophers.

C · Multithreading · POSIX

Philosophers is a multithreaded simulation of the dining-philosophers problem: each philosopher needs two shared forks to eat, while the program must prevent deadlocks and starvation.

I implemented it in C with POSIX threads and mutexes. Each philosopher runs in a separate thread and each fork is protected by a mutex. Ordered lock acquisition removes circular wait conditions and prevents deadlocks.

A monitor thread continuously checks timestamps to detect philosopher death in real time while enforcing strict timing for eating, sleeping, and thinking cycles.