Back to Projects

philosophers

Concurrency and synchronization project written in C.

  • C
  • Makefile

Overview

Philosophers is a concurrency simulation project based on the dining philosophers problem. The goal is to model several workers that share limited resources while keeping their timing, state transitions, and synchronization correct.

Visit the repository for source and setup instructions.

Usage

Build from the philo directory with make, then run the simulation with the required timing arguments:

cd philo
make
./philo 5 800 200 200

The optional fifth argument sets how many meals each philosopher must eat before the simulation stops:

./philo 5 800 200 200 7

What I Built

Details

Shared state and synchronization

Each worker owns its own thread and tracks its last meal time and meal count. Forks are represented by mutexes, while printing and simulation state use their own mutexes so status output and shutdown decisions stay consistent.

Monitoring and shutdown

A monitor thread checks whether a philosopher has exceeded time_to_die or whether every philosopher reached the optional meal quota. Once a terminal condition is reached, the simulation state is updated and workers exit their routines cleanly.

Project rules and limitations

The project is intentionally small and timing-sensitive. It handles the one-philosopher edge case separately and uses short sleeps to avoid busy-waiting too aggressively while still checking shutdown state frequently.

Notes

The project is useful as a compact exercise in thread coordination, shared state ownership, and the kinds of edge cases that show up when timing and synchronization interact.

Sources / Further Reading