Implement waiting for death/fed in the main
authorLukas Jiriste <ljiriste@student.42prague.com>
Thu, 30 May 2024 08:17:06 +0000 (10:17 +0200)
committerLukas Jiriste <ljiriste@student.42prague.com>
Thu, 30 May 2024 09:18:40 +0000 (11:18 +0200)
commit698066112865b42fcce65f2a3e0ad159c4489f38
tree29744f4adad2eb395ba85b63dabcb057fe341053
parenta124a0c436276fb0a6578a940d7b7259580df202
Implement waiting for death/fed in the main

This is only half the protocol implementation. It is complicated
because I cannot use signal handlers to clean after the philosopers.

The basic idea is that an end condition posts the death semaphore.
It is that used and posted imediately by the threads waiting for it.

In main thread waiting for death this ends the thread_fed.
The thread then waits for all philosophers to switch to not alive
so that it can post the term semaphore without any printing.
The term semaphore has to be posted because philosophers may be waiting
for it and would be stuck there forever.

To be implemented in next commit:
In philosopher thread the death semahore couses the alive var to switch
to 0. Additionally the philosopher posts the end semaphore
which (when all philos do so) signals to the main process it can post
the term semaphore.
philo_bonus/hunger_watcher.c
philo_bonus/main.c
philo_bonus/mem_management.c
philo_bonus/philo.h