- There are as many forks as philosophers.
- Every fork object has its own mutex.
- Each philosopher has a
fork[left]
andfork[right]
pointer.
-
number_of_philosophers
The number of philosophers and also the number of forks. -
time_to_die
(in milliseconds): If a philosopher didn’t start eatingtime_to_die
milliseconds since the beginning of their last meal or the beginning of the simulation, they die. -
time_to_eat
(in milliseconds): The time it takes for a philosopher to eat. During that time, they will need to hold two forks. -
time_to_sleep
(in milliseconds): The time a philosopher will spend sleeping. -
number_of_times_each_philosopher_must_eat
(optional argument): If all philosophers have eaten at leastnumber_of_times_each_philosopher_must_eat
times, the simulation stops. If not specified, the simulation stops when a philosopher dies.
-
timestamp_in_ms
X has taken a fork -
timestamp_in_ms
X is eating -
timestamp_in_ms
X is sleeping -
timestamp_in_ms
X is thinking -
timestamp_in_ms
X died -
A displayed state message should not be mixed up with another message.
-
A message announcing a philosopher died should be displayed no more than 10 ms after the actual death of the philosopher.
https://stackoverflow.com/a/40880980
https://stackoverflow.com/questions/53032354/does-atomic-read-guarantees-reading-of-the-latest-value
pthread_create
pthread_detach
pthread_join
pthread_mutex_init
pthread_mutex_destroy
pthread_mutex_lock
pthread_mutex_unlock