summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authoryctct <yctct@yctct.com>2026-09-13 18:58:14 +0200
committeryctct <yctct@yctct.com>2026-09-13 18:58:14 +0200
commit47beba686ff9d2aab63738fba7176a5235703d05 (patch)
treef839ed36a9e9d4476fcdc59379b17903abfa35c8 /src/main.c
Add all files, first commit
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c39
1 files changed, 39 insertions, 0 deletions
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..216e903
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,39 @@
+#include "codexion.h"
+# include <stdlib.h> // or atoi(), malloc()
+
+int main(int argc, char **argv)
+{
+ t_sim *sim;
+ t_philo **philos;
+ t_fork **forks;
+ int ret;
+
+ if (argc != 9)
+ {
+ print_usage();
+ return (0);
+ }
+ if (!valid_params(argv))
+ return (0);
+ sim = create_sim(argv);
+ if (sim == NULL)
+ return (1);
+ start_timer(sim);
+ philos = create_arr_philos(sim);
+ if (philos == NULL)
+ return (1);
+ forks = create_arr_forks(sim);
+ if (forks == NULL)
+ return (1);
+ init_mutex(sim);
+ assign_forks(sim);
+ assign_philos(sim);
+ ret = run_threads(sim);
+ if (ret != 0)
+ return (1);
+ destroy_mutex(sim);
+ free_forks(sim);
+ free_philos(sim);
+ free(sim);
+ return (0);
+}