summaryrefslogtreecommitdiff
path: root/src/main.c
blob: 216e9032d3afefec06373a3df29e215387db4b3b (plain)
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
#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);
}