diff options
| author | Charles Cabergs <me@cacharle.xyz> | 2021-01-14 10:57:02 +0100 |
|---|---|---|
| committer | Charles Cabergs <me@cacharle.xyz> | 2021-01-14 10:57:02 +0100 |
| commit | 0ed344821bc3c872100a18289d0384d51af7e970 (patch) | |
| tree | 8b246d0494eff661bc044aa9b8cc38bf37084efc | |
| parent | 051e5fa4382a629b76f32e46d3e766ed2eb306fc (diff) | |
| download | philosophers-master.tar.gz philosophers-master.tar.bz2 philosophers-master.zip | |
| -rw-r--r-- | philo_one/Makefile | 4 | ||||
| -rw-r--r-- | philo_one/src/main.c | 10 | ||||
| -rw-r--r-- | philo_three/Makefile | 4 | ||||
| -rw-r--r-- | philo_three/src/helper.c | 9 | ||||
| -rw-r--r-- | philo_three/src/main.c | 22 | ||||
| -rw-r--r-- | philo_two/Makefile | 4 |
6 files changed, 23 insertions, 30 deletions
diff --git a/philo_one/Makefile b/philo_one/Makefile index c58aa6e..f40b652 100644 --- a/philo_one/Makefile +++ b/philo_one/Makefile @@ -6,7 +6,7 @@ # By: cacharle <marvin@42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/11/24 05:50:15 by cacharle #+# #+# # -# Updated: 2021/01/08 14:44:00 by charles ### ########.fr # +# Updated: 2021/01/14 10:56:27 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -17,7 +17,7 @@ MAKE = make --no-print-directory COMMONDIR = ../common CC = gcc -CCFLAGS = -std=c99 -O2 -I$(COMMONDIR)/inc -Wall -Wextra #-Werror +CCFLAGS = -g -std=c99 -O2 -I$(COMMONDIR)/inc -Wall -Wextra -Werror LDFLAGS = -lpthread -L$(COMMONDIR) -lphilocommon NAME = philo_one diff --git a/philo_one/src/main.c b/philo_one/src/main.c index 9ac4cfc..e2dabbc 100644 --- a/philo_one/src/main.c +++ b/philo_one/src/main.c @@ -6,7 +6,7 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2019/11/24 05:53:02 by cacharle #+# #+# */ -/* Updated: 2021/01/10 11:51:10 by cacharle ### ########.fr */ +/* Updated: 2021/01/12 12:53:27 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ @@ -44,16 +44,16 @@ static int st_setup( { pthread_t thread_flush; - if (pthread_create(&thread_flush, NULL, - (t_routine)st_routine_flush, (void*)&conf) != 0) - return (1); - pthread_detach(thread_flush); if ((conf->forks = forks_new(conf->philo_num)) == NULL) return (1); if ((*philos = philos_new(conf)) == NULL) return (st_destroy(conf, NULL, NULL, NULL)); if (pthread_mutex_init(&conf->mutex_stdout, NULL) != 0) return (st_destroy(conf, *philos, NULL, NULL)); + if (pthread_create(&thread_flush, NULL, + (t_routine)st_routine_flush, (void*)&conf) != 0) + return (st_destroy(conf, *philos, &conf->mutex_stdout, NULL)); + pthread_detach(thread_flush); if (pthread_mutex_init(&conf->mutex_meal_num_finished_counter, NULL) != 0) return (st_destroy(conf, *philos, &conf->mutex_stdout, NULL)); conf->all_alive = true; diff --git a/philo_three/Makefile b/philo_three/Makefile index cac5e51..96b4005 100644 --- a/philo_three/Makefile +++ b/philo_three/Makefile @@ -6,7 +6,7 @@ # By: cacharle <marvin@42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/11/24 05:50:15 by cacharle #+# #+# # -# Updated: 2021/01/08 15:03:18 by charles ### ########.fr # +# Updated: 2021/01/14 10:56:09 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -17,7 +17,7 @@ MAKE = make --no-print-directory COMMON_DIR = ../common CC = gcc -CCFLAGS = -std=c99 -O2 -I$(COMMON_DIR)/inc -Wall -Wextra #-Werror +CCFLAGS = -std=c99 -O2 -I$(COMMON_DIR)/inc -Wall -Wextra -Werror LDFLAGS = -lpthread -L$(COMMON_DIR) -lphilocommon NAME = philo_three diff --git a/philo_three/src/helper.c b/philo_three/src/helper.c index 3b718bc..a6e4c6e 100644 --- a/philo_three/src/helper.c +++ b/philo_three/src/helper.c @@ -6,19 +6,12 @@ /* By: cacharle <me@cacharle.xyz> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2021/01/10 13:58:26 by cacharle #+# #+# */ -/* Updated: 2021/01/10 14:24:26 by cacharle ### ########.fr */ +/* Updated: 2021/01/14 10:54:26 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "philo_three.h" -void h_destroy_sem(const char *name, sem_t *sem) -{ - if (sem != SEM_FAILED) - sem_close(sem); - sem_unlink(name); -} - bool h_sem_create(const char *name, unsigned int value, sem_t **sem) { if (value == 0) diff --git a/philo_three/src/main.c b/philo_three/src/main.c index a3128a0..158ca25 100644 --- a/philo_three/src/main.c +++ b/philo_three/src/main.c @@ -6,13 +6,13 @@ /* By: cacharle <marvin@42.fr> +#+ +:+ +#+ */ /* +#+#+#+#+#+ +#+ */ /* Created: 2020/02/15 00:45:24 by cacharle #+# #+# */ -/* Updated: 2021/01/10 14:25:49 by cacharle ### ########.fr */ +/* Updated: 2021/01/14 10:54:56 by cacharle ### ########.fr */ /* */ /* ************************************************************************** */ #include "philo_three.h" -static int st_destroy(t_philo_conf *conf, pid_t *pids, long int philo_num) +static int st_destroy(pid_t *pids, long int philo_num) { long int i; @@ -23,12 +23,12 @@ static int st_destroy(t_philo_conf *conf, pid_t *pids, long int philo_num) kill(pids[i], SIGKILL); free(pids); } - h_destroy_sem(PHILO_SEM_NAME, conf->forks); - h_destroy_sem(PHILO_SEM_STDOUT_NAME, conf->sem_stdout); - h_destroy_sem(PHILO_SEM_FINISH_NAME, conf->sem_finish); - h_destroy_sem(PHILO_SEM_MEAL_NUM_NAME, conf->sem_meal_num); - h_destroy_sem(PHILO_SEM_START_NAME, conf->sem_start); - h_destroy_sem(PHILO_SEM_GRAB_NAME, conf->sem_grab); + sem_unlink(PHILO_SEM_NAME); + sem_unlink(PHILO_SEM_STDOUT_NAME); + sem_unlink(PHILO_SEM_FINISH_NAME); + sem_unlink(PHILO_SEM_MEAL_NUM_NAME); + sem_unlink(PHILO_SEM_START_NAME); + sem_unlink(PHILO_SEM_GRAB_NAME); return (1); } @@ -103,16 +103,16 @@ int main(int argc, char **argv) if (conf.philo_num == 0 || conf.meal_num == 0) return (0); if (st_setup(&conf, &pids) != 0 || st_start(&conf, pids, h_time_now()) != 0) - return (st_destroy(&conf, pids, conf.philo_num)); + return (st_destroy(pids, conf.philo_num)); if (conf.meal_num != -1) { if (pthread_create(&thread_meal_num, NULL, (t_routine)st_routine_meal_num, &conf) != 0) - return (st_destroy(&conf, pids, conf.philo_num)); + return (st_destroy(pids, conf.philo_num)); pthread_detach(thread_meal_num); } sem_wait(conf.sem_finish); sem_wait(conf.sem_finish); - st_destroy(&conf, pids, conf.philo_num); + st_destroy(pids, conf.philo_num); return (0); } diff --git a/philo_two/Makefile b/philo_two/Makefile index ccb7ae6..daba027 100644 --- a/philo_two/Makefile +++ b/philo_two/Makefile @@ -6,7 +6,7 @@ # By: cacharle <marvin@42.fr> +#+ +:+ +#+ # # +#+#+#+#+#+ +#+ # # Created: 2019/11/24 05:50:15 by cacharle #+# #+# # -# Updated: 2021/01/08 14:31:50 by charles ### ########.fr # +# Updated: 2021/01/14 10:56:18 by cacharle ### ########.fr # # # # **************************************************************************** # @@ -17,7 +17,7 @@ MAKE = make --no-print-directory COMMONDIR = ../common CC = gcc -CCFLAGS = -std=c99 -Wall -Wextra -Werror -O2 -I$(COMMONDIR)/inc +CCFLAGS = -std=c99 -O2 -I$(COMMONDIR)/inc -Wall -Wextra -Werror LDFLAGS = -lpthread -L$(COMMONDIR) -lphilocommon NAME = philo_two |
