https://github.com/izenynn/philosophers
42 Cursus - philosophers: this project is a training to multi-threads/multi-process programming.
https://github.com/izenynn/philosophers
42 42born2code c linux macos mutex mutex-lock mutex-synchronisation philosophers philosophers-dinner-problem semaphore sempahores threading threads
Last synced: 30 days ago
JSON representation
42 Cursus - philosophers: this project is a training to multi-threads/multi-process programming.
- Host: GitHub
- URL: https://github.com/izenynn/philosophers
- Owner: izenynn
- License: gpl-3.0
- Created: 2021-11-03T18:44:02.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2022-02-21T21:18:53.000Z (over 4 years ago)
- Last Synced: 2025-01-22T05:15:34.110Z (over 1 year ago)
- Topics: 42, 42born2code, c, linux, macos, mutex, mutex-lock, mutex-synchronisation, philosophers, philosophers-dinner-problem, semaphore, sempahores, threading, threads
- Language: C
- Homepage:
- Size: 89.8 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# philosophers
## Info
42 Cursus - philosophers: this project is a training to multi-threads/multi-process programming.
- Status: finished
- Result: 125%
- Observations: (null)
## The philosophers problem
The classic dining philosopher problem.
This problem states that N philosophers seated around a circular table with one fork between each pair of philosophers. A philosopher may eat if he can pick up the two forks adjacent to him. One fork may be picked up by any one of its adjacent followers but not both.
Each time a philosopher finish eating, they will drop drop their forks and start sleeping. Once they have finished sleeping, the will start thinking and waiting to eat.
Simulation stops when a philosopher dies.
Every philosopher needs to eat and they should never starve.
Philosophers do not speak with each other.
Philosophers do not know when another philospher is about to die.
And of course, philosophers should avoid dying.
## Solutions
[philo](https://github.com/izenynn/philosophers/tree/main/philo): philosophers with threads and mutex.
- One fork between each pair of philosophers.
[philo_bonus](https://github.com/izenynn/philosophers/tree/main/philo_bonus): philosophers with processes and semaphore.
- All the forks are in the middle of the table.
## How to use
Clone the repo
```sh
git clone https://github.com/izenynn/libft.git
```
Go to `philo` or `philo_bonus` folder and run `make`
```sh
cd ./philo && make
```
```sh
cd ./philo_bonus && make
```
- *Makefile rules: `all`, `clean`, `fclean`, `re`).*
Usage
```sh
./philo [N PHILOS] [DIE TIME] [EAT TIME] [SLEEP TIME] (OPT)[PHILO EAT N TIMES]
```
- last argument is optional.
- `philo_bonus` takes the same arguments as `philo`.
Example
```sh
./philo 4 800 200 200
```
```sh
./philo_bonus 10 410 200 200 7
```
##
[](https://forthebadge.com)
[](https://forthebadge.com)