Skip to content

Commit d49f1d6

Browse files
committed
Unify TLC models for barriers
Adding descriptions
1 parent 872c7c0 commit d49f1d6

7 files changed

Lines changed: 45 additions & 34 deletions

File tree

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
CONSTANT N = 7
1+
CONSTANT N = 6
22
SPECIFICATION Spec
3-
INVARIANT TypeOK
3+
INVARIANT TypeOK
4+
PROPERTY BarrierProperty

specifications/barriers/Barrier.tla

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,9 @@ Spec == Init /\ [][Next]_vars
3232
TypeOK ==
3333
/\ pc \in [ProcSet -> {"b0", "b1"}]
3434

35+
\* A process cannot leave the barrier if there are still other processes
36+
\* that need to enter it
37+
BarrierProperty ==
38+
/\ [][\A p,q \in ProcSet : pc[p] = "b0" /\ pc[q] = "b1" => pc'[q] = "b1"]_vars
39+
3540
===============================================================================
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1-
CONSTANT N = 7
1+
CONSTANT N = 6
22
SPECIFICATION Spec
33
INVARIANTS TypeOK LockInv Inv FlushInv
4+
PROPERTY BSpec

specifications/barriers/Barriers.tla

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ CONSTANTS
66
N
77

88
(**
9-
--algorithm Barrier {
9+
--algorithm Barriers {
1010
variables
11-
lock = 1,
12-
gate_1 = 0,
13-
gate_2 = 0,
14-
rdv = 0;
11+
lock = 1, \* lock variable used for critical sections
12+
gate_1 = 0, \* semaphore for the first chamber
13+
gate_2 = 0, \* semaphore for the second chamber
14+
rdv = 0; \* counts the processes entering/leaving the barrier
1515

1616
macro Lock(l) {
1717
await l = 1;
@@ -31,28 +31,38 @@ CONSTANTS
3131
s := s + N;
3232
}
3333

34+
\* The algorithm uses two waiting chambers which wait for all processes to
35+
\* to enter before allowing them to continue.
36+
\* The usage of two chambers ensures no process can leave the barrier and
37+
\* pass through the whole barrier again while blocking others inside.
3438
process (proc \in 1..N) {
3539
a0: while (TRUE) {
3640
skip; \* Some code
41+
\* first waiting chamber a1-a6
3742
a1: Lock(lock);
38-
a2: rdv := rdv + 1;
43+
a2: rdv := rdv + 1; \* protect read/write of shared variable with a lock
3944
a3: if (rdv = N) {
45+
\* when all processes are in the first chamber
4046
a4: Signal(gate_1);
47+
\* open the chamber
4148
};
4249
a5: Unlock(lock);
4350
a6: Wait(gate_1);
51+
\* second waiting chamber a7-a12
4452
a7: Lock(lock);
45-
a8: rdv := rdv - 1;
53+
a8: rdv := rdv - 1; \* protect read/write of shared variable with a lock
4654
a9: if (rdv = 0) {
55+
\* when all processes are in the second chamber
4756
a10: Signal(gate_2);
57+
\* open the chamber
4858
};
4959
a11: Unlock(lock);
5060
a12: Wait(gate_2);
5161
}
5262
}
5363
}
5464
**)
55-
\* BEGIN TRANSLATION (chksum(pcal) = "fa4cafb2" /\ chksum(tla) = "4cd2e9fd")
65+
\* BEGIN TRANSLATION (chksum(pcal) = "7a2331f4" /\ chksum(tla) = "4cd2e9fd")
5666
VARIABLES pc, lock, gate_1, gate_2, rdv
5767

5868
vars == << pc, lock, gate_1, gate_2, rdv >>
@@ -239,6 +249,7 @@ pc_translation(self) ==
239249
ELSE "b1"
240250

241251
B == INSTANCE Barrier WITH pc <- [p \in ProcSet |-> pc_translation(p)]
252+
BSpec == B!Spec
242253

243254
-------------------------------------------------------------------------------
244255

specifications/barriers/MCBarriers.cfg

Lines changed: 0 additions & 3 deletions
This file was deleted.

specifications/barriers/MCBarriers.tla

Lines changed: 0 additions & 6 deletions
This file was deleted.

specifications/barriers/README.md

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,26 @@
11
# Barrier synchronization
2-
-
2+
3+
## Barrier.tla
4+
5+
A specification of an abstract Barrier.
6+
7+
The usual typing `TypeOK` invariant is defined.
8+
9+
Another property to show that processes cannot leave the barrier as long as
10+
there are others outside of it is also given (see `BarrierProperty`)
11+
12+
A model with $N = 6$ that verifies both properties is provided.
313

414
## Barriers.tla
515

616
A specification of a Reusable Barrier synchronization facility using as
717
presented in the INFO09012 Parallel Programming course in ULiège by
818
Prof. Pascal Fontaine.
919

10-
The barrier consists of two waiting rooms `a1-a6` and `a7-a12`.
11-
The last process entering a waiting room signals the appropriate semaphore
20+
The barrier consists of two waiting chambers `a1-a6` and `a7-a12`.
21+
The last process entering a waiting chamber signals the appropriate semaphore
1222
and allows processes to pass to the next section.
13-
Using two such waiting rooms makes sure a process leaving the barrier cannot
23+
Using two such waiting chambers makes sure a process leaving the barrier cannot
1424
reenter and pass through the whole barrier again.
1525

1626
## Invariants
@@ -26,20 +36,12 @@ reenter and pass through the whole barrier again.
2636
- `FlushInv` are two additional clauses needed to prove the refinement.
2737
It shows that once a waiting section is opened, all processes can pass.
2838

29-
A model `Barriers.cfg` with $N = 7$ that verifies these four invariants is
39+
A model `Barriers.cfg` with $N = 6$ that verifies these four invariants is
3040
provided.
3141

3242
## Refinement
3343

3444
A refinement towards an abstract Barrier specification is proven with TLAPS.
3545

3646
A model `MCBarriers.cfg` and its companion `MCBarriers.tla` verifies if
37-
`B!Spec` (the abstract Barrier specification) holds for `Spec`
38-
39-
## Barrier.tla
40-
41-
A specification of an abstract Barrier.
42-
43-
The usual typing invariant is defined.
44-
45-
A model with the same amount of processes as above is provided.
47+
`B!Spec` (the abstract Barrier specification) holds for `Spec`

0 commit comments

Comments
 (0)