https://github.com/maripeshko/42_philosophers
The project of 42Berlin school. Learning the basics of threading, deadlock and data race.
https://github.com/maripeshko/42_philosophers
deadlock
Last synced: about 2 months ago
JSON representation
The project of 42Berlin school. Learning the basics of threading, deadlock and data race.
- Host: GitHub
- URL: https://github.com/maripeshko/42_philosophers
- Owner: MariPeshko
- Created: 2024-11-23T17:50:19.000Z (11 months ago)
- Default Branch: main
- Last Pushed: 2024-12-14T01:02:05.000Z (10 months ago)
- Last Synced: 2025-08-23T06:02:20.394Z (about 2 months ago)
- Topics: deadlock
- Language: C
- Homepage:
- Size: 1.62 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# 42_Philosophers
### "The unexamined life is not worth living."
— Socrates42Berlin school project created by Maryna Peshko (mpeshko) in November of 2024. Studying the basics of multithreading. More details in the topic "Philosophers.subject.pdf"
### Logic
The two most important functions to understand a logic:
* `void *routine(void *arg)`
* `int ft_fork(t_philo *philo)`
* `int ft_think(t_philo *philo)`
In routine() all even philosophers start later than all odd ones.
```
if (philo->philo_id % 2 == 0)
ft_usleep(5);
```
`ft_fork()` has diferrent logic in taking forks for even and odd philosophers.
`ft_think()` is used to delay a philosopher before he takes a fork, so that he doesn't get there early and steal it from another philosopher who waited longer. This prevents some philosopher from waiting too long for his fork and dying.### The program input:
`./philo`
` [number_of_philosophers]`
` [time_to_die]`
` [time_to_eat]`
` [time_to_sleep]`
` _(optional argument)`_
` [number_of_times_each_philosopher_must_eat]`
According to the subject, all tests are limited to 200 philosophers, and the minimum time is 60 ms.### Examples
Philosopher should not eat and should die.
`./philo 1 800 200 200`
No Philosopher should die.
`./philo 5 800 200 200`
No Philosopher should die and the simulation should stop when every philosopher has eaten at least 7 times.
`./philo 5 800 200 200 3`
No Philosopher should die.
`./philo 4 410 200 200`
One Philosopher should die.
`./philo 4 299 200 100`
One Philosopher should die.
`./philo 10 299 2000 100`
No one should die
`./philo 10 299 2000 100`
Parsing tests
`./philo 2 "" "" ""`
`./philo -2 100 100 100`
`./philo f 100 100 100`### How to check for data races
`valgrind --tool=helgrind`### How to check used function
`nm -u ./philo`
### Contacts
https://www.linkedin.com/in/maryna-peshko/
email: marunapeshko@gmail.com(c) Maryna Peshko