Skip to content

aliciamurma/Philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

amurcia-'s 42 Philosophers Score

Philosophers

Mandatory

One or more philosophers sit at a round table.
There is a large bowl of spaghetti in the middle of the table.
The philosophers alternatively eat, think, or sleep.

There are as many forks as philosophers. There is one fork between each pair of philosophers.
A philosopher takes their right and their left forks to eat, one in each hand.

When a philosopher has finished eating, they put their forks back on the table and start sleeping.
Once awake, they start thinking again.

The simulation stops when a philosopher dies of starvation.

Arguments:
  1. The number of philosophers (and forks).
  2. (in milliseconds): If a philosopher didn’t start eating at this time since the beginning of their last meal or the beginning of the simulation, they die.
  3. (in milliseconds): The time it takes for a philosopher to eat. During that time, they will need to hold two forks.
  4. (in milliseconds): The time a philosopher will spend sleeping.
  5. (optional argument): If all philosophers have eaten at least that number of times, the simulation stops.

Each philosopher must be a thread.
Use mutex for forks and to use printf.

You can't have more than 10ms between the death of a philosopher and the moment you print their death.

Try not to kill your poor philosophers.

example image

Instructions

Compile and execute the progra in philo folder
make run

Bonus

All the forks are put in the middle of the table.
They have no states in memory but the number of available forks is represented by a semaphore.
Each philosopher should be a process. But the main process should not be a philosopher.

Instructions

Compile and execute the program in philo_bonus folder
make run

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published