/* By: ljiriste <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/03/05 12:49:40 by ljiriste #+# #+# */
-/* Updated: 2024/03/19 13:39:27 by ljiriste ### ########.fr */
+/* Updated: 2024/03/19 14:14:15 by ljiriste ### ########.fr */
/* */
/* ************************************************************************** */
#include <stdio.h>
#include <unistd.h>
+static const char *g_fed_str = "All philosophers are well fed";
// unsigned long would be more apropriate for min_eats_num
// but for the ease of parsing I'm using size_t
typedef struct s_settings
res = res || parse_arg(argv[3], &set->time_to_eat);
res = res || parse_arg(argv[4], &set->time_to_sleep);
if (argc == 6)
+ {
res = res || parse_args(argv[5], &set->min_eats_num);
+ if (set->min_eats_num == 0)
+ set->end = 1;
+ }
else
set->min_eats_num = 0;
return (res);
if (all_full)
{
pthread_mutex_lock(&set->terminal);
- printf("%li All philosophers are well fed\n", (cur_time_sus() - set->program_start) / 1000);
+ printf("%li %s\n", (cur_time_sus() - set->program_start) / 1000, g_fed_str);
set->end = 1;
pthread_mutex_unlock(&set->terminal);
return ;
printf("Invalid input arguments.\n");
return (1);
}
+ if (settings.end)
+ {
+ printf("0 %s\n", g_fed_str);
+ return (0);
+ }
if (settings.philo_count == 1)
return (handle_single_philo(&settings));
threads = malloc(sizeof(pthread_t) * settings.philo_count);