-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrwlock.tla
55 lines (45 loc) · 1.34 KB
/
rwlock.tla
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
------------------------------- MODULE rwLock -------------------------------
EXTENDS Integers, Sequences
VARIABLES readers, waitingWriters, writer, queue
Init ==
/\ readers = 0
/\ waitingWriters = 0
/\ writer = FALSE
/\ queue = <<>>
TryAcquireRLock ==
/\ waitingWriters = 0
/\ writer = FALSE
/\ readers' = readers + 1
/\ queue' = queue
/\ UNCHANGED <<waitingWriters, writer, queue>>
TryAcquireWLock ==
/\ writer = FALSE
/\ readers = 0
/\ waitingWriters' = waitingWriters - 1
/\ writer' = TRUE
/\ UNCHANGED readers
/\ queue' = Append(queue, "Write")
ReleaseRLock ==
/\ readers > 0
/\ readers' = readers - 1
/\ UNCHANGED << writer, waitingWriters, queue>>
ReleaseWLock ==
/\ writer = TRUE
/\ writer' = FALSE
/\ waitingWriters' = waitingWriters - 1
/\ UNCHANGED readers
/\ queue' = Tail(queue)
Next ==
\/ TryAcquireRLock
\/ ReleaseRLock
\/ TryAcquireWLock
\/ ReleaseWLock
Spec == Init /\ [][Next]_<<readers, waitingWriters, writer, queue>>
TypeInvariant ==
/\ readers \in Nat
/\ waitingWriters \in Nat
/\ writer \in {TRUE, FALSE}
=============================================================================
\* Modification History
\* Last modified Wed May 08 17:32:21 CST 2024 by 18367
\* Created Mon Apr 01 00:32:31 CST 2024 by 18367