aboutsummaryrefslogtreecommitdiff
path: root/philo/src/main.c
diff options
context:
space:
mode:
authorDominik Kaiser2025-01-28 14:29:21 +0100
committerDominik Kaiser2025-01-28 14:29:21 +0100
commitfe3e739d151d76d4c9a7bd62226bbc8efa21700f (patch)
tree6bf58ec4a885f6d4c6396dca73a6c2e303235de4 /philo/src/main.c
parentc33bbb4f66dbaca2f02b6f32c2d6bdb84be5f115 (diff)
downloadPhilosophers-fe3e739d151d76d4c9a7bd62226bbc8efa21700f.tar.gz
Philosophers-fe3e739d151d76d4c9a7bd62226bbc8efa21700f.zip
Destroy Mutexes
Diffstat (limited to 'philo/src/main.c')
-rw-r--r--philo/src/main.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/philo/src/main.c b/philo/src/main.c
index c928795..85bd230 100644
--- a/philo/src/main.c
+++ b/philo/src/main.c
@@ -6,11 +6,12 @@
/* By: dkaiser <dkaiser@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025/01/14 17:13:30 by dkaiser #+# #+# */
-/* Updated: 2025/01/28 13:49:55 by dkaiser ### ########.fr */
+/* Updated: 2025/01/28 14:25:27 by dkaiser ### ########.fr */
/* */
/* ************************************************************************** */
#include "philo.h"
+#include <pthread.h>
int load_data(t_phdata *data, int argc, char *argv[])
{
@@ -38,6 +39,21 @@ int load_data(t_phdata *data, int argc, char *argv[])
return (EXIT_SUCCESS);
}
+void free_data(t_phdata *data)
+{
+ int i;
+
+ i = 0;
+ while (i < data->nbr_of_philos)
+ {
+ pthread_mutex_destroy(&data->forks[i].mutex);
+ i++;
+ }
+ free(data->forks);
+ pthread_mutex_destroy(&data->pme_mutex);
+ pthread_mutex_destroy(&data->sr_mutex);
+}
+
int main(int argc, char *argv[])
{
t_phdata data;
@@ -54,6 +70,6 @@ int main(int argc, char *argv[])
return (result);
result = run_simulation(data.nbr_of_philos, philos, &data);
free(philos);
- free(data.forks);
+ free_data(&data);
return (result);
}