forked from runtimeverification/k
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreads.k
More file actions
60 lines (53 loc) · 1.88 KB
/
Copy paththreads.k
File metadata and controls
60 lines (53 loc) · 1.88 KB
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
// Copyright (c) 2012-2019 K Team. All Rights Reserved.
require "int.k"
require "seq.k"
module THREADS-SYNTAX imports SEQ-SYNTAX
imports INT-EXP-SYNTAX
syntax Exp ::= "acquire" Exp [acq, strict]
| "release" Exp [rel, strict]
| "rendezvous" Exp [rndv, strict]
> "spawn" Exp [spwn]
endmodule
module THREADS
imports THREADS-SYNTAX
imports SEQ
imports INT-EXP
configuration <thread multiplicity="*">
<k> .K </k> <holds> .Map </holds>
</thread>
<busy> .Set </busy>
rule [spawn-thread] :
<thread>... <k>spawn S
=> skip ...</k> ...</thread>
(. => <thread>... <k>S</k> ...</thread>) [transition]
rule [end-thread] :
(<thread>... <k>V:Val</k> <holds>Holds:Map</holds>
...</thread> => .) <busy>Busy:Set
=> Busy -Set keys(Holds)</busy> [transition]
rule [free-acquire] :
<k>acquire V:Val
=> skip ...</k> <holds>... .Map
=> V|->0 ...</holds>
<busy>Busy (.Set
=> SetItem(V))</busy>
when notBool(V in Busy:Set) [transition]
rule [reentrant-acquire] :
<k>acquire V:Val
=> skip ...</k> <holds>... V|->(N
=> N +Int 1) ...</holds>
rule [reentrant-release] :
<k>release V:Val
=> skip ...</k> <holds>... V|->(N
=> N -Int 1) ...</holds>
when N >Int 0
rule [release] :
<k>release V:Val
=> skip ...</k> <holds>... (V|->0
=> .Map) ...</holds>
<busy>... (SetItem(V)
=> .Set) ...</busy>
rule [rendezvous] :
<k>rendezvous V:Val
=> skip ...</k> <k>rendezvous V
=> skip ...</k> [transition]
endmodule