-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcanibal.pfc
62 lines (52 loc) · 910 Bytes
/
canibal.pfc
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
program canibal;(*MisioneroCanales*)
const MAXC = 10;
NPORC = 3;
var comer : array [1..MAXC] of channel of synchronous;
repone: channel of synchronous;
process type Tcanibal(id: integer);
begin
repeat
comer[id] ! any;
WriteLN('canibal ... ',id,' comiendo');
forever;
end;
process cocinero;
begin
repeat
repone ? any;
WriteLN('Cocinero repone');
sleep(10);
forever;
end;
process marmita;
var n,porciones : integer;
begin
porciones := 0;
repeat
pri select
for n:=1 to MAXC replicate
when porciones >0 =>
comer[n] ? any;
porciones := porciones -1;
or
when porciones = 0 =>
repone ! any;
porciones := NPORC;
end;(*select*)
forever;
end;
var
canib: array [1..MAXC] of Tcanibal;
i,j: integer;
begin
(*initial(mutex,1);*)
cobegin
Cocinero;
Marmita;
for i:=1 to MAXC do
canib[i](i);
coend;
end.
canibales
cocinero
marmita