From: Lukas Jiriste Date: Tue, 19 Mar 2024 12:42:49 +0000 (+0100) Subject: Implement handling of a lone philosopher X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=4ad2c3719a61f7b3c0158e28babdc68ad2e35b3c;p=42%2Fphilosophers_old.git Implement handling of a lone philosopher --- diff --git a/philo/main.c b/philo/main.c index 0d2d0db..0b73acc 100644 --- a/philo/main.c +++ b/philo/main.c @@ -6,7 +6,7 @@ /* By: ljiriste +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2024/03/05 12:49:40 by ljiriste #+# #+# */ -/* Updated: 2024/03/19 11:55:01 by ljiriste ### ########.fr */ +/* Updated: 2024/03/19 13:39:27 by ljiriste ### ########.fr */ /* */ /* ************************************************************************** */ @@ -339,6 +339,16 @@ void check_death(t_philo *philos, t_settings *set) } } +int handle_single_philo(t_settings *set) +{ + set->program_start = cur_time_sus(); + thread_print(set, 1, "is thinking"); + thread_print(set, 1, "has taken a fork"); + usleep(set->time_to_die); + thread_print(set, 1, "died"); + return (0); +} + int main(int argc, char **argv) { t_settings settings; @@ -351,6 +361,8 @@ int main(int argc, char **argv) printf("Invalid input arguments.\n"); return (1); } + if (settings.philo_count == 1) + return (handle_single_philo(&settings)); threads = malloc(sizeof(pthread_t) * settings.philo_count); forks = init_forks(settings.philo_count); philos = build_philos(forks, &settings);