summary |
shortlog | log |
commit |
commitdiff |
tree
first ⋅ prev ⋅ next
Lukas Jiriste [Thu, 26 Sep 2024 08:09:49 +0000 (10:09 +0200)]
Make philos drop a fork when the other is taken
Instead of making a fork a mutex, it now holds its state - whether it is
taken. This makes it possible for a philo to check, whether he can grab
both forks and if they cannot, they won't hold any fork.
I thought about approach before but my mind was locked onto using the
function pthread_mutex_trylock which is not permitted by the subject.
Lukas Jiriste [Thu, 5 Sep 2024 09:43:59 +0000 (11:43 +0200)]
Make the sleep between death check be max 100 us
This is implemented so that main checks well fed condition more
frequently. Without the well fed condition can be satisfied for a long
time before main notices, particularly for long time_to_death.
Lukas Jiriste [Thu, 5 Sep 2024 09:32:45 +0000 (11:32 +0200)]
Make main wait for a possible philo death
This makes main less demanding as it also enters sleep when no
philosopher's death is near.
Lukas Jiriste [Fri, 10 May 2024 06:47:59 +0000 (08:47 +0200)]
Remove whitespace from end of lines in Makefile
Lukas Jiriste [Thu, 9 May 2024 10:42:34 +0000 (12:42 +0200)]
Further change cleanup order
To make helgrind errors disappear, delete every mutex shared between
threads only after joining all the threads. This ensures that
no thread can access a mutex after the removal of the mutex because
no thread exists then.
Lukas Jiriste [Thu, 9 May 2024 10:38:31 +0000 (12:38 +0200)]
Add the check for well fed philosophers
Lukas Jiriste [Thu, 9 May 2024 09:59:59 +0000 (11:59 +0200)]
Format to comply with the 42 Norm
Lukas Jiriste [Thu, 9 May 2024 09:19:16 +0000 (11:19 +0200)]
Add missing index increment, change cleanup order
The program only checked the forst philo for starvation.
The change in the cleanup order is needed because without the change
(forks) mutexes were deinitialized before joining the (philo) threads.
This could lead to a philo waiting for a fork, which has just been
cleared, leading to undefined behavior (endless wait). When the main
thread joins all the threads it gets gets stuck in the one waitin for
a fork.
Lukas Jiriste [Thu, 9 May 2024 09:06:09 +0000 (11:06 +0200)]
Join the threads for valgrind not to complain
Lukas Jiriste [Thu, 9 May 2024 09:00:54 +0000 (11:00 +0200)]
Fix discrepancy caused by confusing ms and us
Lukas Jiriste [Thu, 9 May 2024 08:27:02 +0000 (10:27 +0200)]
Implement checking for the death of philosopher
Also minor refactoring
Lukas Jiriste [Thu, 9 May 2024 07:41:44 +0000 (09:41 +0200)]
Implement the philo actions
Lukas Jiriste [Thu, 28 Mar 2024 13:56:54 +0000 (14:56 +0100)]
Implement seat_philosophers
Thanks to the change of how the program keeps track of time
it is possible to set the "last_eaten" member of philo in advance
(to zero - the start) without slowing the seating.
Thanks to this, no delay is necessary before the program checks whether
philos died of hunger. (It was needed in old branch, because
philosophers initialized their own time at the start of their
existance, and the check could happen before the time was set)
Lukas Jiriste [Thu, 28 Mar 2024 13:49:02 +0000 (14:49 +0100)]
Add initialization of some members of philos
Lukas Jiriste [Thu, 28 Mar 2024 11:01:32 +0000 (12:01 +0100)]
Fix allocation of wrong size
The way the allocation was written, it allocated space for pointer
instead of the structure pointed to. This has been corrected.
Lukas Jiriste [Thu, 28 Mar 2024 10:54:47 +0000 (11:54 +0100)]
Fix logic bug
Lukas Jiriste [Thu, 28 Mar 2024 10:40:14 +0000 (11:40 +0100)]
Implement conditional compilation
Before this commit, compilation would stop at file parsing.c
with error (warning + -Werror) caused by -Wtype-limits.
Conditional compilation is added so that the offending if statement
is not present, when not needed.
The #if directive could have only been set up around the problematic
if statement. The 42 Norm however forbids using macros anywhere but
the global scope.
This made me write the the affected functions twice, which then broke
the 5 function limit per .c file. Hence this commit is quite large
for such a small change.
Lukas Jiriste [Thu, 28 Mar 2024 09:55:38 +0000 (10:55 +0100)]
Implement initialization, cleanup and mutex struct
The mutex struct is implemented because pthread_mutex_destroy
produces undefined behaviour when supplied with uninitialized mutex.
The struct holds information whether the mutex has been initialized
succesfully.
The header file philo.h has also been filled with declarations of
functions used in main so that Makefiles compiles every file to object.
This is done for easier checking of compile errors.
Lukas Jiriste [Thu, 28 Mar 2024 08:38:54 +0000 (09:38 +0100)]
Remove unnecessary include
Lukas Jiriste [Thu, 28 Mar 2024 08:33:12 +0000 (09:33 +0100)]
Implement parsing of input
Lukas Jiriste [Tue, 26 Mar 2024 10:10:42 +0000 (11:10 +0100)]
Add Makefile (doesn't compile yet)
Lukas Jiriste [Tue, 26 Mar 2024 08:55:55 +0000 (09:55 +0100)]
Change the context of the time variables
This change is preliminary as the code that handles this is yet to be
written. I decided to do this because I think it will not add any
complexity but will make the code more portable (as useconds_t needs
not be huge this way)?
Lukas Jiriste [Tue, 26 Mar 2024 08:13:48 +0000 (09:13 +0100)]
Create outline of the solution
Lukas Jiriste [Fri, 22 Mar 2024 09:49:13 +0000 (10:49 +0100)]
Add .gitignore as an initial commit