42/philosophers.git
20 months agoFix 2 bugs introduced by refactoring
Lukas Jiriste [Fri, 22 Mar 2024 08:24:05 +0000 (09:24 +0100)]
Fix 2 bugs introduced by refactoring

The bugs where introduced in commit f41587f.

One bug was that not setting the optional argument
number_of_times_each_philosopher_must_eat behaved the same
as setting it to 0.

The other bug was caused by not initializing a value.
This caused the non-philosopher thread to sleep for much too long.

20 months agoRefactor main.c to multiple files to pass the Norm
Lukas Jiriste [Thu, 21 Mar 2024 09:49:35 +0000 (10:49 +0100)]
Refactor main.c to multiple files to pass the Norm

20 months agoRefactor functions to comply with the Norm
Lukas Jiriste [Tue, 19 Mar 2024 14:40:23 +0000 (15:40 +0100)]
Refactor functions to comply with the Norm

20 months agoMake a loop in check_death less busy
Lukas Jiriste [Tue, 19 Mar 2024 13:41:48 +0000 (14:41 +0100)]
Make a loop in check_death less busy

This change makes the main thread sleep for the time it would
take the "most hungry" philosopher to die. It is thus guaranteed
that no philosopher may die during the sleep.

20 months agoStart the refactor of this project
Lukas Jiriste [Tue, 19 Mar 2024 13:35:36 +0000 (14:35 +0100)]
Start the refactor of this project

20 months agoReplace string literals with global string consts
Lukas Jiriste [Tue, 19 Mar 2024 13:20:48 +0000 (14:20 +0100)]
Replace string literals with global string consts

This is done to have a consistent output for special cases as
changes have to only be made in one spot.

20 months agoAdd handling of special case
Lukas Jiriste [Tue, 19 Mar 2024 13:14:35 +0000 (14:14 +0100)]
Add handling of special case

Handle the case where number_of_times_each_philosopher_must_eat is 0.

20 months agoImplement handling of a lone philosopher
Lukas Jiriste [Tue, 19 Mar 2024 12:42:49 +0000 (13:42 +0100)]
Implement handling of a lone philosopher

20 months agoAdd the number_of_times_each_philosopher_must_eat
Lukas Jiriste [Tue, 19 Mar 2024 11:33:16 +0000 (12:33 +0100)]
Add the number_of_times_each_philosopher_must_eat

This option required minor code changes, because I tried to prepare
for this in advance but I had an incorrect understanding of the option.

20 months agoAdd missing indexing on initialization
Lukas Jiriste [Tue, 19 Mar 2024 10:32:07 +0000 (11:32 +0100)]
Add missing indexing on initialization

20 months agoAdd parantheses around return value
Lukas Jiriste [Tue, 19 Mar 2024 10:30:21 +0000 (11:30 +0100)]
Add parantheses around return value

20 months agoFix leak caused by not accepting thread's return
Lukas Jiriste [Tue, 19 Mar 2024 10:23:36 +0000 (11:23 +0100)]
Fix leak caused by not accepting thread's return

The threads have alocatted memory where return value resides.
A thread has to be joined (or detached) to release this memory.

20 months agoImplement mandatory part of philosophers
Lukas Jiriste [Thu, 7 Mar 2024 16:52:47 +0000 (17:52 +0100)]
Implement mandatory part of philosophers

Sorry for big commit, I wrote it in one session and didn't encounter
an apropriate point for partial commit.
This needs to be tested and refactored to pass the 42 Norm.

20 months agoAdd .gitignore as an initial commit
Lukas Jiriste [Fri, 22 Mar 2024 09:49:13 +0000 (10:49 +0100)]
Add .gitignore as an initial commit