Skip to content

Commit

Permalink
finish and test dining simulation; still missing: single philo and al…
Browse files Browse the repository at this point in the history
…so want to return thread routine fct status
  • Loading branch information
Alexander Schenk committed Oct 11, 2024
1 parent aa7ed88 commit d77036f
Show file tree
Hide file tree
Showing 14 changed files with 5,934 additions and 330 deletions.
13 changes: 8 additions & 5 deletions philo/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
# By: aschenk <aschenk@student.42berlin.de> +#+ +:+ +#+ #
# +#+#+#+#+#+ +#+ #
# Created: 2024/09/03 14:29:17 by aschenk #+# #+# #
# Updated: 2024/10/08 11:07:13 by aschenk ### ########.fr #
# Updated: 2024/10/11 19:43:22 by aschenk ### ########.fr #
# #
# **************************************************************************** #

Expand All @@ -24,15 +24,18 @@ NAME := philo
SRCS_DIR := src
SRCS_FILES := main.c \
1_check_args.c \
2_init_sim.c \
3_run_sim.c \
dining_rules.c \
2_init_philos.c \
3_init_sim.c \
4_eat.c \
5_eat_sleep_think.c \
6_monitor.c \
7_run_sim.c \
utils/0_libft.c \
utils/1_print_action.c \
utils/1_print_error.c \
utils/2_mutex.c \
utils/3_time.c \
utils/free.c \
utils/4_free.c \

SRCS := $(addprefix $(SRCS_DIR)/, $(SRCS_FILES))

Expand Down
16 changes: 13 additions & 3 deletions philo/include/philo.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: aschenk <aschenk@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/08/14 19:21:56 by aschenk #+# #+# */
/* Updated: 2024/10/09 13:53:09 by aschenk ### ########.fr */
/* Updated: 2024/10/11 19:52:51 by aschenk ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -82,18 +82,28 @@ the risk of starvation among others while still prioritizing their own needs.

int check_args(int argc, char **argv);

// 2_init_philos.c

int init_philos(t_sim *sim);

// 2_init_sim.c

int init_sim(t_sim **sim, int argc, char **argv);

// 3_eat.c

int pick_forks_and_log(t_philo *philo);
int eat_and_log(t_philo *philo, int t_eat);
int is_philo_full(t_philo *philo, int max_meals);

// 3_run_sim.c

int run_sim(t_sim *sim);

// X_dining.c

void *dining(void *arg);
void *monitoring(void *arg);
void *eat_sleep_think(void *arg);
void *monitor(void *arg);

// utils/0_libft.c

Expand Down
4 changes: 3 additions & 1 deletion philo/include/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* By: aschenk <aschenk@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/09/19 17:19:12 by aschenk #+# #+# */
/* Updated: 2024/10/10 14:23:40 by aschenk ### ########.fr */
/* Updated: 2024/10/11 12:25:02 by aschenk ### ########.fr */
/* */
/* ************************************************************************** */

Expand Down Expand Up @@ -92,6 +92,8 @@ typedef struct s_philo
pthread_t thread_id;
int meals_eaten;
t_ull t_last_meal;
t_mtx mtx_last_meal;
int mtx_last_meal_init;
t_ull timestamp_death;
t_fork *left_fork;
t_fork *right_fork;
Expand Down
Loading

0 comments on commit d77036f

Please sign in to comment.