#include "philo.h" int diff_time(t_time old, struct timeval new) { return ((new.tv_sec - old.ts) * 1000 + (new.tv_usec - old.tu) / 1000); } int is_dead(t_philo *philo) { struct timeval stime; int time; if (philo->global->n_eat == philo->params->n_phi) { philo->global->dead = 1; return (1); } gettimeofday(&stime, NULL); time = diff_time(philo->t_last_meal, stime); if (time >= philo->params->t_die) { philo->global->dead = 1; print_message(philo, B_RED, "died", 0); return (1); } return (0); } void launch_threads(t_philo *philo, pthread_t *id) { int i; i = 0; while (i < philo->params->n_phi) { pthread_create(&id[i], NULL, &philo_exec, philo); philo = philo->next; i++; } while (philo->global->dead == 0) { is_dead(philo); philo = philo->next; } i = 0; while (i < philo->params->n_phi) { pthread_create(&id[i], NULL, &philo_exec, philo); philo = philo->next; i++; } }