Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/t-h2o/42-philosophers
Philosophers dinner problem
https://github.com/t-h2o/42-philosophers
42 c philosophers-dinner-problem
Last synced: about 17 hours ago
JSON representation
Philosophers dinner problem
- Host: GitHub
- URL: https://github.com/t-h2o/42-philosophers
- Owner: t-h2o
- License: gpl-3.0
- Created: 2022-03-29T14:48:17.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-08-22T16:24:53.000Z (about 2 years ago)
- Last Synced: 2023-03-04T00:43:23.069Z (over 1 year ago)
- Topics: 42, c, philosophers-dinner-problem
- Language: C
- Homepage:
- Size: 111 KB
- Stars: 0
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# 42-philosophers
```draw
P: Philosopher
F: ForkTable:
P1 F1 P2 F2 P3 F3P1 need F3 and F1
P2 need F1 and F2
P3 need F2 and F3t1: P1 eat
t1: p2 [NOTHING]
t1: p3 [NOTHING]t2: p1 sleep
t2: P2 eat
t2: p3 [NOTHING]t3: p1 thinks
t3: p2 sleep
t3: P3 eatt4: p1 eat
t4: p2 think
t4: P3 spleep
```### What a life
The main loop:
1. lock the two forks
2. eat
1. lock message
2. write the message
3. unlock message
4. wait the eat time
3. unlock the two forks
4. sleep
1. lock message
2. write the message
3. unlock message
4. wait the sleep time
5. think
1. lock message
2. write the message
3. unlock message
4. wait available fork## Informations
### Difference between processes and threads
#### process
The process will duplicate his data into the child.
#### thread
Every threads share the same data.
## Resources
* CodeVault Videos: [Unix Threads in C](https://youtube.com/playlist?list=PLfqABt5AS4FmuQf70psXrsMLEDQXNkLq2)
* Wikipedia: [Dining philosophers problem](https://en.wikipedia.org/wiki/Dining_philosophers_problem)
* Wikipedia: [Philosopher](https://en.wikipedia.org/wiki/Philosopher)