RealConrad / 42philosophers

I never thought philosophy would be so deadly

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

📗 Philosophers

The classic synchronization and multi-threaded philosopher dining problem.

Developed using  


Table Of Content

Features

  • Visual representation of the problem and solution (prints out the current philosopher state).
  • Real-time status updates of each philosopher.
  • Adjustable parameters for the simulation.
  • Clean and well-commented code for better understanding.
  • Once the simulation should be stopped (a philosopher died or all philosophers have eaten the given amount) , it joins all threads and frees memory.

How It Works

The Dining Philosophers problem is a classic synchronization and multi-threaded problem which demonstrates the challenges of ensuring that multiple threads share resources without conflicts. In this project, [number of philosophers] philosophers sit at a round table, each with a bowl of spaghetti and a fork between each adjacent pair. The philosophers have 3 states, thinking, eating and sleeping. If they are thinking they cannot be eating, if they are eating they cannot be sleeping etc.. However, a philosopher needs both forks to eat, and must pick them up one at a time. This scenario leads to a number of synchronization issues which are addressed and solved in this implementation.

Installation

Clone the repository

git clone https://github.com/RealConrad/42philosophers.git

Navigate to the project directory

cd 42philosophers/philo/

Compile the project

make

Usage

NOTE: ms = milliseconds

./philo [number_of_philosophers] [time_to_die_ms] [time_to_eat_ms] [time_to_sleep_ms] [OPTIONAL: eat_count]

Example:

./philo 4 600 200 200 5

License

MIT

About

I never thought philosophy would be so deadly

License:MIT License


Languages

Language:C 92.4%Language:Makefile 7.6%