42 school project
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1 KiB

3 years ago
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* 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 nont 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