├── .gitignore
├── 2pc.tla
├── ABProtocol.tla
├── Bakery.tla
├── BoundedBuffer.tla
├── BoundedBuffer2.tla
├── BoundedChannel.tla
├── Dekker.tla
├── Dekker2.tla
├── DieHard.tla
├── EuclidSedgewickpstyle.tla
├── FairProcess.cfg
├── FairProcess.tla
├── FastMutex.tla
├── Hello.tla
├── Increment.tla
├── LICENSE
├── MessageBatchDrainTest.tla
├── MessageBatchDrainTest2.tla
├── MessageBatchDrainTest3.tla
├── OneBitClock.cfg
├── OneBitClock.tla
├── OneBitProtocol.tla
├── PCalBoundedChannel.tla
├── RAFT.tla
├── README.md
├── TwoPhaseCommit.cfg
├── TwoPhaseCommit.tla
├── add.tla
├── eu.tla
├── euclid.tla
├── test.cfg
└── test.tla
/.gitignore:
--------------------------------------------------------------------------------
1 | *~
2 | *.iws
3 | *.ipr
4 | *.iml
5 | .project
6 | .classpath
7 | .factorypath
8 | .settings/
9 | .idea/
10 | .DS_Store
11 | classes/
12 | build.properties
13 | dist/
14 | atlassian*
15 | keystore/
16 | tmp/
17 | bla*.java
18 | doc/manual/*.css
19 | doc/manual/build/*
20 | doc/manual/*.tmp
21 | doc/tutorial/build/*
22 | doc/tutorial/*.css
23 | conf/MANIFEST.MF
24 | target/
25 | lib/
26 | *.toolbox
27 | *.old
28 | *.cfg
29 |
30 |
31 |
--------------------------------------------------------------------------------
/2pc.tla:
--------------------------------------------------------------------------------
1 | -------------------------------- MODULE 2pc --------------------------------
2 |
3 | EXTENDS Naturals, Integers, FiniteSets, Bags, Sequences, TLC
4 |
5 | (* PlusCal options (-termination) *)
6 |
7 |
8 | (*
9 |
10 | --algorithm 2pc {
11 | variables participants={"A", "B", "C"},
12 | states=[i\in participants |-> "start"]; \* states can be "start", "prepared" / "failed", "committed" / "aborted"
13 |
14 | process(name="P") {
15 | p0: print "hello";
16 | }
17 |
18 | }
19 |
20 | *)
21 | \* BEGIN TRANSLATION
22 | VARIABLES participants, states, pc
23 |
24 | vars == << participants, states, pc >>
25 |
26 | Init == (* Global variables *)
27 | /\ participants = {"a", "b", "c"}
28 | /\ states = [i\in participants |-> "start"]
29 | /\ pc = "Lbl_1"
30 |
31 | Lbl_1 == /\ pc = "Lbl_1"
32 | /\ PrintT("start")
33 | /\ pc' = "Done"
34 | /\ UNCHANGED << participants, states >>
35 |
36 | Next == Lbl_1
37 | \/ (* Disjunct to prevent deadlock on termination *)
38 | (pc = "Done" /\ UNCHANGED vars)
39 |
40 | Spec == Init /\ [][Next]_vars
41 |
42 | Termination == <>(pc = "Done")
43 |
44 | \* END TRANSLATION
45 |
46 |
47 | =============================================================================
48 | \* Modification History
49 | \* Last modified Wed Mar 25 08:41:58 CET 2015 by bela
50 | \* Created Wed Mar 25 08:25:16 CET 2015 by bela
51 |
--------------------------------------------------------------------------------
/ABProtocol.tla:
--------------------------------------------------------------------------------
1 | ----------------------------- MODULE ABProtocol -----------------------------
2 | EXTENDS Naturals, Sequences, TLC
3 | (* the input array of messages to the algorithm *)
4 | CONSTANT Msg
5 |
6 | (* PlusCal options (-termination) *)
7 |
8 | (* define remove operation*)
9 | Remove(i,seq) == [ j \in 1..(Len(seq)-1) |-> IF j < i THEN seq[j] ELSE seq[j+1]]
10 |
11 | (*
12 | --algorithm ABProtocol
13 | { variables input = <<>>; output = <<>>; msgC = <<>>; ackC = <<>>;
14 |
15 | macro Send(m, chan) { chan := Append(chan,m) }
16 | macro Rcv(v, chan) { await chan # <<>>;
17 | v := Head(chan);
18 | chan := Tail(chan)}
19 |
20 | process (Sender = "S")
21 | variables next = 1; sbit = 0; ack;
22 | { s: while (TRUE) {
23 | either with (m \in Msg) { input := Append(input, m)} \* grab message from user to send
24 | or { await next <= Len(input) ; \* wait until message is available, then send next message
25 | Send(<>, msgC)}
26 | or { Rcv(ack, ackC); \* receive acknowledgement and set up for next message
27 | if (ack = sbit) { next := next+1;
28 | sbit := (sbit+1)%2 }}}}
29 |
30 | process (Receiver = "R")
31 | variables rbit = 1; msg;
32 | { r: while (TRUE) {
33 | either Send(rbit,ackC) \* send current acknowledgement
34 | or { Rcv(msg, msgC); \* receive next message (unconditional) and deliver if has correct abit
35 | if (msg[2] # rbit) { rbit := (rbit+1)%2 ;
36 | output := Append(output, msg[1])}}}}
37 |
38 | process (LoseMsg = "L")
39 | { l: while (TRUE) {
40 | either with (i \in 1..Len(msgC)) { msgC := Remove(i, msgC)} \* drop a randomly chosen message
41 | or with (i \in 1..Len(ackC)) {ackC := Remove(i, ackC) }}} \* drop a randomly chosen ack
42 |
43 | } (* end ABProtocol *)
44 |
45 | *)
46 | \* BEGIN TRANSLATION
47 | CONSTANT defaultInitValue
48 | VARIABLES input, output, msgC, ackC, next, sbit, ack, rbit, msg
49 |
50 | vars == << input, output, msgC, ackC, next, sbit, ack, rbit, msg >>
51 |
52 | ProcSet == {"S"} \cup {"R"} \cup {"L"}
53 |
54 | Init == (* Global variables *)
55 | /\ input = <<>>
56 | /\ output = <<>>
57 | /\ msgC = <<>>
58 | /\ ackC = <<>>
59 | (* Process Sender *)
60 | /\ next = 1
61 | /\ sbit = 0
62 | /\ ack = defaultInitValue
63 | (* Process Receiver *)
64 | /\ rbit = 1
65 | /\ msg = defaultInitValue
66 |
67 | Sender == /\ \/ /\ \E m \in Msg:
68 | input' = Append(input, m)
69 | /\ UNCHANGED <>
70 | \/ /\ next <= Len(input)
71 | /\ msgC' = Append(msgC,(<>))
72 | /\ UNCHANGED <>
73 | \/ /\ ackC # <<>>
74 | /\ ack' = Head(ackC)
75 | /\ ackC' = Tail(ackC)
76 | /\ IF ack' = sbit
77 | THEN /\ next' = next+1
78 | /\ sbit' = (sbit+1)%2
79 | ELSE /\ TRUE
80 | /\ UNCHANGED << next, sbit >>
81 | /\ UNCHANGED <>
82 | /\ UNCHANGED << output, rbit, msg >>
83 |
84 | Receiver == /\ \/ /\ ackC' = Append(ackC,rbit)
85 | /\ UNCHANGED <