Skip to content

Latest commit

 

History

History
116 lines (89 loc) · 4.69 KB

README.md

File metadata and controls

116 lines (89 loc) · 4.69 KB

Philosophers

In computer science, The Dining Philosopher Problem is an example problem often used in concurrent algorithm design to illustrate synchronization issues and techniques for resolving them.

What is Philosophers?

Philosophers is an individual project at 42 that requires us to solve The Dining Philosopher Problem problem using threads, processes, mutex and semaphores. The mandatory part must be solved using threads and mutex. The solution was implemented using a monitoring thread, which checks if any philosopher has died and warns others to stop (locking mutex). The bonus consists of using processes instead of threads and semaphores instead of mutex, to solve it the solution used was to implement the death check between the sleeping times, avoiding the problem of reporting the death of a philosopher with more than 10ms.

Problem statement

The problem was proposed by Edsger W. Dijkstra in 1965 and is considered one of the classic problems about operating systems. The problem consists of five philosophers sitting around a circular dinner table, where each philosopher has a plate for eating spaghetti and a fork to his right. To eat they need 2 forks but there is only one fork between each pair of plates. A philosopher has three actions: eating, thinking, or sleeping. When a philosopher gets hungry he will try to take the fork to his right and to his left, one at a time. If he manages to get both forks, he will eat the food at a certain time and will put the forks on the table, going to sleep and then going to think again.

Preview

Mandatory vs Bonus

alt text

Badge

Objectives

  • Unix logic

Skills

  • Rigor
  • Imperative programming
  • Unix

My grade

Getting started

Follow the steps below

# Clone the project and access the folder
git clone https://github.com/wwwwelton/philosophers && cd philosophers/

# Access the folder philo for the program that uses threads and mutex
cd philo

# or

# Access the folder philo_bonus for the program that uses processes and semaphores
cd philo_bonus

# Run make so you can build the program
make

# Run the program with the example arguments
./philo 5 800 200 200 10

# or

# Run the program with the example arguments for the bonus part
./philo_bonus 5 800 200 200 10

# Clean output objects with
make fclean

# Well done!

Arguments

All arguments working with mandatory and bonus

Arguments Usage

#1 #2 #3 #4 #5
5 800 200 200 10
number_of_philosophers time_to_die time_to_eat time_to_sleep *number_of_times_each_must_eat
*The last argument, number_of_times_each_must_eat is optional.

Updating

The project is regularly updated with bug fixes and code optimization.

📝 License

This project is licensed under the GNU General Public License v3.0 - see the LICENSE file for details.


Made by Welton Leite 👋 See my linkedin