Skip to content

About

Dining philosophers problem

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

62 Commits

Folders and files

Repository files navigation

This project has been created as part of the 42 curriculum by nkojima.

Description

Philosophers is the mandatory threading exercise from the 42 curriculum. The philo program simulates the dining philosophers problem: each philosopher runs in its own thread, shares forks with neighbors, and must eat, sleep, and think without data races, deadlocks, or incorrect death detection.

Each philosopher repeatedly takes two forks, eats, sleeps, and thinks. A separate monitor thread checks whether a philosopher has gone too long without starting a meal and stops the simulation on death or when every philosopher has eaten enough times (optional fifth argument). Forks are protected with mutexes; philosophers reserve both forks before locking them, then acquire the mutexes in a fixed order to avoid deadlock.

Instructions

Build

make -C philo

Run

./philo/philo number_of_philosophers time_to_die time_to_eat time_to_sleep \
  [number_of_times_each_philosopher_must_eat]

Examples:

./philo/philo 5 800 200 200
./philo/philo 5 800 200 200 7
./philo/philo 1 800 200 200

Tests

make -C philo test
make -C philo norm

Resources

How AI was used

AI tools (Cursor / Claude) were used for:

  • Drafting and refining docs/design.md (mutex layout, lock order, test matrix)
  • Reviewing concurrency and subject compliance on feature branches
  • Designing fork reservation and turn-based scheduling to stabilize no-death test cases
  • README and wording review

All simulation logic, mutex layout, and final code were written and verified by the author (build, unit tests, and manual scenario runs).

About

Dining philosophers problem

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages