How 2czu/philosophers works
This C program runs a command-line Dining Philosophers simulation: arguments initialize shared state and fork mutexes, philosopher threads alternate actions, and a monitor stops the run on starvation or when the optional meal limit is met. The graph separates setup, thread orchestration, philosopher actions, and shared-state utilities. Relationships are limited to calls visible in the excerpts or described in the README; the header defines shared structures and interfaces.
Main entry points: simulation.c Thread orchestration · main.c Program entry · actions.c Philosopher actions · init.c Argument and state setup
Components 10
Setup and lifecycle
- Program entry
src/main.c - Argument and state setup
src/init.c - Simulation structures
philosopher.h - Thread and mutex cleanup
src/cleanup.c
Simulation runtime
- Thread orchestration
src/simulation.c - Philosopher actions
src/actions.c
Shared state and utilities
- Shared-state accessors
src/accessors_1.c - Stop-state accessors
src/accessors_2.c - Time and status utilities
src/utils.c
Other components
- CLI user
Connections 13
- CLI user → Program entry: starts
README.md - Program entry → Argument and state setup: initializes
src/main.c - Argument and state setup → Simulation structures: populates
src/init.c - Program entry → Thread orchestration: starts and monitors
src/main.c - Thread orchestration → Philosopher actions: runs
src/simulation.c - Philosopher actions → Shared-state accessors: updates and reads meal state
src/actions.c - Thread orchestration → Shared-state accessors: checks meal state
src/simulation.c - Philosopher actions → Stop-state accessors: checks stop state
src/actions.c - Thread orchestration → Stop-state accessors: sets and checks stop state
src/simulation.c - Philosopher actions → Time and status utilities: times and prints
src/actions.c - Thread orchestration → Time and status utilities: checks time
src/simulation.c - Program entry → Thread and mutex cleanup: frees state
src/main.c - Thread and mutex cleanup → Thread orchestration: joins threads
src/cleanup.c