narnaud
3 years ago
4 changed files with 8 additions and 75 deletions
@ -1,71 +0,0 @@ |
|||
/* ************************************************************************** */ |
|||
/* */ |
|||
/* ::: :::::::: */ |
|||
/* philosophers.h :+: :+: :+: */ |
|||
/* +:+ +:+ +:+ */ |
|||
/* By: narnaud <narnaud@student.42.fr> +#+ +:+ +#+ */ |
|||
/* +#+#+#+#+#+ +#+ */ |
|||
/* Created: 2022/05/16 14:03:01 by narnaud #+# #+# */ |
|||
/* Updated: 2022/05/16 14:03:20 by narnaud ### ########.fr */ |
|||
/* */ |
|||
/* ************************************************************************** */ |
|||
|
|||
#ifndef PHILOSOPHERS_H |
|||
# define PHILOSOPHERS_H |
|||
|
|||
/*
|
|||
|
|||
• Chaque philosophe doit être représenté par un thread. |
|||
• Toutes les fourchettes sont au centre de la table. |
|||
• Elles n’ont pas d’état spécifique en mémoire, mais le nombre de fourchettes |
|||
disponibles est représenté par un sémaphore. • Chaque philosophe est représenté |
|||
par un processus différent. Cependant, le processus principal ne doit pas être |
|||
un philosophe. |
|||
|
|||
*/ |
|||
|
|||
# include <unistd.h> |
|||
# include <stdio.h> |
|||
# include <stdlib.h> |
|||
# include <pthread.h> |
|||
# include <string.h> |
|||
# include <errno.h> |
|||
# include <fcntl.h> |
|||
# include <signal.h> |
|||
# include <sys/wait.h> |
|||
# include <sys/time.h> |
|||
# include <sys/stat.h> |
|||
# include <semaphore.h> |
|||
|
|||
typedef struct s_table t_table; |
|||
|
|||
typedef struct s_philo |
|||
{ |
|||
int id; |
|||
size_t meals_done; |
|||
size_t last_meal_time; |
|||
t_table *table; |
|||
} t_philo; |
|||
|
|||
typedef struct s_table |
|||
{ |
|||
size_t nb_of_philos; |
|||
size_t time_to_die; |
|||
size_t eating_time; |
|||
size_t sleeping_time; |
|||
size_t nb_of_meal; |
|||
int i; |
|||
sem_t *sptr; |
|||
sem_t *death; |
|||
t_philo *philos; |
|||
size_t time; |
|||
size_t start_time; |
|||
int *pid; |
|||
} t_table; |
|||
|
|||
/***************************/ |
|||
|
|||
t_table *parsing(char **argv); |
|||
size_t gettime(void); |
|||
|
|||
#endif |
Loading…
Reference in new issue