Skip to content

jelloster/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🍴 The Dining Philosophers Problem 🍴

Dining Philosophers

Project Topics

  • Thread synchronization
  • Mutex handling
  • Deadlock and datarace prevention

The Problem

A number of philosophers sit at a round table. Each one has a fork (or a chopstick in other versions) to their side. The philosophers think so hard that they need to keep eating at a certain rate to avoid dying of overexhaustion. Sadly, in order to eat, the philosopher must use two forks. How will the philosophers pace their eating and share their forks in order to avoid dying?

The Program

This program runs a simulation of philosophers in the described situation. The philosophers eat 🍽️, sleep 💤 and think 💭 and these actions are printed out as timestamped logs. The simulation ends if a philosopher dies.

Program

Installation

Clone the project using the following command

git clone https://github.com/jelloster/philosophers.git

Running the program

  1. Navigate into the project folder

cd philosophers

  1. Compile the project with make

make

  1. Run the program and give it the following input:

./philo <num of philos> <time to die (ms)> <time to eat (ms)> <time to sleep (ms)> <(optional) max meals per philo>

Example:

./philo 4 210 100 100

This translates to:

  • 4 Philosophers
  • Time to die : 210 ms
  • Time to eat : 100 ms
  • Time to sleep : 100 ms

About

A simulation of the well known dining philosopher problem

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors