-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo
84 lines (66 loc) · 2.58 KB
/
todo
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
**The philosophers dinner problem**
* there are a table and there are philosophers around it
* the philo must eat or think or sleep, they should do one process
* every philo must have his own fork
* the philo must eat with two forks, his left and right fork
* if the philo finished eating, he puts their forks on the table and start sleeping, once awake he start thinking
* the program stops when a philo dies of starvation
* (eating -> sleeping -> thinking : repeat)
==============================================
* program arguments :
./philo number_of_philo time_to_die(ms) time_to_eat(ms) time_to_sleep(ms) numbers_time_to_eat(optional)
6 1
5 . 2
4 3
* each philo has number ranging form 1 ro N
* philo number N sits next to philo N-1 and N+1
in case i gave optional parameter
=> 5
in case i havent
==> -1
===> 19990000000 ====> 19990000100 ===> 100 printf
/*
create a struct that wold contain general information
when did the simulation start
arr philos
arr forks
*/
/*
pthread_create
pthread_join
pthread_detash
pthread_mutex_lock
pthread_mutex_unlock
*/
// 200 Philos : array of structs 200 philos
// usleep custom made for sleeping in ms getcurrenttime()
// 200 Forks : Initialize array of 200 forks of type pthead_mutex_t
/* ROUTINE CONDITIONS */
/*
1. PHILO HAS DIED
2. PHILO HAS REACHED ITS LIMIT == TIMES_EATEN == 0
*/
// Ittereate through philosephers
// Fill information for each philo
// Itterate through each philosephers giving it the fuction routine
// should put to sleep the even philos
// The odd should start the routine
// need to lock his fork with othread_mutex_lock
//printf has taken a fork
// lock the fork next to him
// start eating (printf statring to eat)
//suspend program by time to eat
// update last_eaten
// update philo_times eaten
// philo->times_eaten--;
// unlock the forks
// put the philo to slee;
// variable so that all philos have access to it
// once this variablr turn true then no other thread can run the routine
// so we should return to the main function
// Create a monitoring function :
// itterate through each philo
// check is current_time - lasteaten < time to die
// a philo has died
// lock the printf mutex so that no ither thread can run printf
// kill all philosephers