A simple yet robust solution to Dining Philosophers in pthread
Do not copy contents of this repo for course assignments. You should take the responsibility for any form of plagiarism.
Philo | State | Fork | Held by |
---|---|---|---|
[ 0]: | Thinking | [ 0]: | Free |
[ 1]: | Eating | [ 1]: | 1 |
[ 2]: | Waiting | [ 2]: | 1 |
[ 3]: | Terminated | [ 3]: | 2 |
[ 4]: | Eating | [ 4]: | 4 |
[ 5]: | Thinking | [ 5]: | 4 |
[ 6]: | Thinking | [ 6]: | Free |
[ 7]: | Thinking | [ 7]: | Free |
[ 8]: | Eating | [ 8]: | 8 |
[ 9]: | Thinking | [ 9]: | 8 |
Th= 5 | Wa= 1 Ea= 3 | Use= 7 | Avail= 3 |
- Compilation:
gcc DPP.c -o DPP -Wall -pthread
- Run:
./DPP <N> <S> <T>
N = number of philosophers
S = random number seed
T = seconds of running