Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Philosophers is a 42 school project simulating multiple philosophers sitting around a table, each with a plate of spaghetti and a fork on their left and right. They share forks with their neighbors to eat. The program uses multithreading and synchronization to prevent deadlocks and starvation. It handles a variable number of philosophers and forks

License

NotificationsYou must be signed in to change notification settings

iLucasPires/philo

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 

Repository files navigation

OSLanguageGradeStatus

Philosophers

This project is about using threads and mutexes to solve theDining 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 repositorygit clone https://github.com/iLucasPires/philo.git
  • Enter the project foldercd philo
  • Runmake 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

About

Philosophers is a 42 school project simulating multiple philosophers sitting around a table, each with a plate of spaghetti and a fork on their left and right. They share forks with their neighbors to eat. The program uses multithreading and synchronization to prevent deadlocks and starvation. It handles a variable number of philosophers and forks

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp