Fix deadlock, introduce another bug bonus
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 13 Jun 2024 16:32:21 +0000 (18:32 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 13 Jun 2024 16:32:21 +0000 (18:32 +0200)
commit6ec9922e7bb5943c13c4b3afdf5bf6a5d0cb0d01
tree1a65ef5bb84dc59677b77d0704d7964e0016a10b
parentfe8281a5c2c19cc2d408a6b47b671858235826a9
Fix deadlock, introduce another bug

The deadlock would happen in the case that 2 philosophers starve at
almost the same time. Their starvation_watchers both leave their loop
and one continues as usual - posting death and turning its philo dead.

The philos, that didn't yet turn dead through the end watcher but
the one starvation watcher that triggered but didn't win the terminal
has the philo locked (it would turn the philo dead if it got the term)
but that makes the end watcher unable to make the philo dead.

This is solved by introducing another lock so that the philo is locked
even though the end watcher is not. The problem now is that neither
normal (not double) death ends the philos nor the "well fed" end.
philo_bonus/helpers.c
philo_bonus/philo.c
philo_bonus/philo.h
philo_bonus/watchers.c