Skip to content

About

Dining philosophers in C: pthreads and mutexes, plus a bonus with processes and semaphores.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

SyncMaster: The dining philosophers with pthreads and mutexes, plus a bonus built on processes and semaphores.

SyncMaster or Table of Threads in this projects i developed a simulation inspired by the "Dining Philosophers" problem to explore concurrency, race conditions, and resource management in multithreaded environments. The project required managing shared resources among multiple "philosophers" (threads) who alternated between thinking and eating. The focus was on preventing race conditions, avoiding deadlocks, and ensuring no starvation of threads. By utilizing mutexes and semaphores, I implemented efficient synchronization mechanisms to guarantee thread safety and proper resource allocation. This project significantly enhanced my skills in concurrent programming, thread synchronization, and the prevention of common pitfalls like race conditions and deadlocks.

Five philosophers around a table; each fork is a mutex; P1 locks fork 1 then fork 2 Gantt chart of ./philo 5 800 200 200 showing eating, sleeping and thinking Bonus version: parent process forks one child per philosopher; forks are a named semaphore

Run it

cd philo && make
./philo 5 800 200 200        # philosophers, time_to_die, time_to_eat, time_to_sleep (ms)
./philo 5 800 200 200 7      # optional: stop once everyone has eaten 7 times
cd ../philo_bonus && make && ./philo_bonus 5 800 200 200

Diagrams in docs/ are generated SVGs, drawn to match the code in this repo.

About

Dining philosophers in C: pthreads and mutexes, plus a bonus with processes and semaphores.

Topics

Resources

Stars

2 stars

Watchers

1 watching

Forks

Releases

Packages

Contributors

Languages