-
Notifications
You must be signed in to change notification settings - Fork 0
/
philosopher2.pml
45 lines (34 loc) · 1.06 KB
/
philosopher2.pml
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
/* Dining Philosophers Problem */
/*
Student 1:Adam Wendelin
Student 2:Victoria Catalán
*/
#define n 5
bool think[n], eat[n] = false;
mtype {fork, none};
mtype cutlery[n] = fork;
proctype phil(int id) {
int left=id; int right = (id +1) % n;
Think: atomic {eat[id] = false; think[id] = true};
printf("Philosopher %d is thinking\n", id);
if :: right < left;
atomic{cutlery[right] == fork -> cutlery[right] = none};
atomic{cutlery[left] == fork -> cutlery[left] = none};
:: left<right;
atomic{cutlery[left] == fork -> cutlery[left] = none};
atomic{cutlery[right] == fork -> cutlery[right] = none};
fi;
Eat: assert (cutlery[right] == none && cutlery[left] == none);
atomic { think[id] = false; eat[id] = true};
printf("Philosopher %d is eating\n", id);
Stop: cutlery[left] = fork; cutlery[right] = fork;
goto Think;
}
init{
int i = 0;
do
:: i>= n -> break
:: else -> run phil(i);
i++
od
}