Skip to content

Latest commit

 

History

History
45 lines (33 loc) · 2.19 KB

README.md

File metadata and controls

45 lines (33 loc) · 2.19 KB

OS Language Grade Status

Philosophers

This project is about using threads and mutexes to solve the Dining Philosophers problem.

Introduction

The project consists of simulating the behavior of philosophers at a dinner table. Each philosopher has a fork on his left and right. To eat, a philosopher needs both forks. To avoid deadlock, a philosopher must always pick up the fork on his right first, then the fork on his left. When he finishes eating, he puts down both forks so that the other philosophers can eat. The simulation stops when a philosopher dies.

How to use

  • Clone the repository git clone https://github.com/iLucasPires/philo.git
  • Enter the project folder cd philo
  • Run make to compile the project
  • Run ./philo <number_of_philosophers> <time_to_die> <time_to_eat> <time_to_sleep> [number_of_times_each_philosopher_must_eat] to execute the program

Requirements

Mandatory part

  • The program must not have any memory leaks and data races.
  • Each philosopher must be a thread
  • Any change of status of a philosopher must be written as follows: timestamp_philosopher_number status
  • The status can be: is eating, is sleeping, is thinking, died
  • The timestamp is the time in milliseconds since the beginning of the simulation.
  • You can’t have more than 10 ms between the death of a philosopher and when it will print its death.
  • Each philosopher should eat at least 1 time before dying.
  • The simulation stops when a philosopher dies.
  • All philosophers must eat at least number_of_times_each_philosopher_must_eat times.

Example

Example