-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.c
More file actions
41 lines (37 loc) · 1.74 KB
/
Copy pathmain.c
File metadata and controls
41 lines (37 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* main.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dporhomo <dporhomo@student.42prague.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2026/06/07 19:56:41 by dporhomo #+# #+# */
/* Updated: 2026/06/14 01:23:39 by dporhomo ### ########.fr */
/* */
/* ************************************************************************** */
/* Main program: parses input, init mutexes, runs the program
cleans meamory, distroy mutexes, terminates operation */
#include "codexion.h"
int main(int argc, char **argv)
{
t_program prog;
t_coder *coders;
int i;
if (!parse_input(argc, argv, &prog))
return (printf("Error: Invalid arguments\n"), 1);
if (!init_mutexes_and_coders(&prog, &coders))
return (printf("Error: Malloc failed\n"), 1);
prog.sim_active = 1;
prog.start_time = get_current_time();
i = -1;
while (++i < prog.num_coders)
pthread_create(&coders[i].thread_id, NULL, coder_routine, &coders[i]);
pthread_create(&prog.monitor_thread, NULL, monitor_routine, coders);
pthread_join(prog.monitor_thread, NULL);
i = -1;
while (++i < prog.num_coders)
pthread_join(coders[i].thread_id, NULL);
clean_mutexes_and_coders(&prog, coders);
printf("--- Simulation Finished Safely ---\n");
return (0);
}