Back to projects

42 project

Philosophers

A concrete introduction to concurrency, threads and synchronization problems.

Stack

  • C
  • Threads
  • Mutex

Skills gained

  • Creating and synchronizing multiple threads
  • Using mutexes to protect shared resources
  • Understanding deadlock and race condition risks
  • Reasoning about time, state and concurrency

Links

Philosophers is an implementation of the classic dining philosophers problem. The project introduces the basics of concurrent programming: threads, mutexes, synchronization, shared access and race conditions.

01 — Concurrency

Everyone wants the fork.

The dining philosophers problem is easy to explain, but much harder to implement correctly. Multiple threads share limited resources, and the goal is to prevent them from blocking each other or corrupting shared state.

Illustration of philosophers sharing resources around a table
Fig. 01
One table, a few forks, and suddenly a full course on synchronization.

02 — Synchronization

Avoiding chaos.

Mutexes help control access to shared resources, but they also introduce new risks. The project pushes you to think about action ordering, waiting times and situations where multiple threads depend on each other.

The nightmare of multitherads.
Fig. 02

03 — Timing

Time becomes critical.

Time management is central in Philosophers. The program must precisely track states, detect blocking situations and avoid unpredictable behavior. It helped me better understand how difficult reliable concurrent code can be.

Illustration of a concurrent program monitoring time
Fig. 03