Skip to content

toagne/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 

Repository files navigation

philosophers

A simulation of the classic Dining Philosophers problem implemented in C using threads and mutexes. This project was developed to explore concepts in concurrency, synchronization, and thread safety while building a deterministic, deadlock-free simulation.

Objective

To simulate a group of philosophers sitting at a table, each alternating between thinking, eating, and sleeping. The simulation must:

  • Prevent deadlocks and starvation
  • Log each philosopher’s actions precisely
  • Terminate cleanly when a philosopher dies or the simulation ends

Features

  • Multi-threaded Simulation
    • Each philosopher is represented by an independent thread.
  • Fork Control with Mutexes\
    • Shared forks are protected by mutexes to ensure mutual exclusion and prevent data races.
  • Time-sensitive Logging
    • Each action (take fork, eat, sleep, think, die) is logged with a timestamp (in ms) relative to the simulation start.
  • Death Detection
    • A monitoring thread observes the state of each philosopher and stops the simulation if a philosopher has not eaten in time.
  • Custom Parameters
    • The simulation behavior can be configured via command-line arguments:
      • ./philo number_of_philosophers time_to_die time_to_eat time_to_sleep [number_of_times_each_philosopher_must_eat]

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published