Skip to content

42sin/philosophers

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


Logo

Philosophers

The Dining Philosopher Problem

Table of Contents
  1. About The Project
  2. Installation
  3. Usage
  4. License

About The Project

Subject PDF

This project is about the Dining Philosophers problem, which is a classic synchronization and concurrency problem that illustrates challenges in avoiding deadlock and ensuring the proper use of resources among multiple threads/processes. The challenge is to design a solution that avoids deadlock and ensures that philosophers can make progress without conflicts. There were several restrictions by the subject. The program must not have any data races, only a few standard library functions were allowed and the project must follow the 42 Norm. For more informations check out the Subject PDF.

(back to top)

Getting Started

Installation

  1. Clone the repo
    git clone https://github.com/42sin/philosophers.git && cd philosophers
  2. Compile (philo for threads & mutexes/philo_bonus for processes & semaphores)
    cd philo && make
  3. Run
    ./philosophers <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep>

(back to top)

Usage

To run the program a few variables are needed:

  1. number_of_philosophers: The amount of philosophers and also the number of forks.
  2. time_to_die: In milliseconds, If a philosopher doesn’t start eating ’time_to_die’ milliseconds after starting their last meal or the beginning of the simulation, he dies.
  3. time_to_eat: In milliseconds, The time it takes for a philosopher to eat. During that time they will need to keep their forks.
  4. time_to_sleep: In milliseconds, The time the philosopher will spend sleeping.
  5. number_of_times_each_philosopher_must_eat: If all philosophers eat at least ’number_of_times_each_philosopher_must_eat’ the simulation will stop. If not specified, the simulation will stop only at the death of a philosopher.

Each action of a philosopher will result in his state being printed with a timestamp and his number.
A philosopher can:
  • grab a fork
  • eat
  • sleep
  • think
  • die

Here is a basic example of a running simulation.

(back to top)

License

Distributed under the MIT License. See LICENSE for more information.

(back to top)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published