-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchPrg-RepairBrokenItems.pml
79 lines (71 loc) · 2.23 KB
/
chPrg-RepairBrokenItems.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
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
/* QUESTION
* Client sends item to mover for repairing & counts the no. of items recieved.
* Clients breaks after sending 100 items & also asserts if repaired is greater than broken.
* Mover forwards items recieved from client to repairService &
* those from repairService to the client.
* RepairService repairs an item recieved with (3/4) propability and sends back.
*/
/*
* CLIENT --> MOVER --> REPAIRSERVICE
* 2 RENDEZVOUS CHANNELS : 1 client-mover channel ~ cm
* & 1 mover-repairservice ~ mr
* i.e. atomic channels (send followed by recieve)
*/
mtype = {BROKEN, REPAIRED}
chan cm = [0] of {mtype};
chan mr = [0] of {mtype};
active proctype client() {
mtype item, itemR;
int b=0, r=0, sum=0;
sum=b+r;
do
:: sum<100
-> if //randomnly decide item quality
:: item = BROKEN
:: item = REPAIRED
fi
atomic{ printf("\n %d client sent %e", sum+1, item); cm!item // send item to mover
if // if mover reads channel, then client waits for reply
:: empty(cm) -> cm?itemR; printf("\tclient recieved item %d as %e", sum+1, itemR);
fi
if // check & count recieved item
:: itemR == BROKEN -> b++;
:: itemR == REPAIRED -> r++;
fi
sum=b+r; // record no. of items sent
}
:: else // when 100 items sent across cm channel to mover
-> atomic{
assert(r>b); // check if repaired is more than broken
if
:: r>b -> printf("\n\n !! REPAIRED count is high !!\n\n")
:: r<b -> printf("\n\n !! BROKEN count is high !!\n\n")
fi
break;} // & break
od
}
active proctype repairservice() {
mtype item;
do
:: mr?item; // wait until an item is recieved
atomic {
if // non-deterministically repair a broken item
:: item == BROKEN -> item = REPAIRED // (3/4) chance that a broken item is repaired
:: item == BROKEN -> item = REPAIRED
:: item == BROKEN -> item = REPAIRED
:: item == BROKEN -> item = BROKEN
:: item == REPAIRED -> item = REPAIRED
fi
printf("\t item %e", item);
mr!item; // send repaired item to mover
}
od
}
active proctype mover(){
mtype item;
do
:: cm?item -> mr!item;
:: mr?item -> cm!item;
// :: empty(cm) -> atomic{ mr?item; cm!item;}
od
}