projects
/
satcheck.git
/ blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
history
|
raw
|
HEAD
Commit state of repository at time of OOPSLA 2015 submission.
[satcheck.git]
/
benchmarks
/
checkfence
/
dekker
/
dekker-fences.c.in
1
#include "lsl_protos.h"
2
/*
3
* Dekker's critical section algorithm, implemented with fences.
4
*
5
* URL:
6
* http://www.justsoftwaresolutions.co.uk/threading/
7
*/
8
9
10
int flag0, flag1;
11
int turn;
12
13
int var = 0;
14
15
void p0() {
16
flag0 = 1;
17
18
while (flag1) {
19
if (turn != 0) {
20
flag0=0;
21
while (turn != 0) {
22
lsl_assume(false);
23
}
24
flag0=1;
25
} else {
26
lsl_assume(false);
27
}
28
}
29
30
// critical section
31
var=1;
32
33
turn=1;
34
flag0=0;
35
}
36
37
void p1() {
38
flag1=1;
39
40
while (flag0) {
41
if (turn != 1) {
42
flag1=0;
43
while (turn!=1) {
44
lsl_assume(false);
45
}
46
flag1=1;
47
} else {
48
lsl_assume(false);
49
}
50
}
51
// critical section
52
var=2;
53
turn=0;
54
flag1=0;
55
}
56
57
void init() {
58
flag0=0;
59
flag1=0;
60
turn=0;
61
}
62
63
void p0l() {
64
int i;
65
for(i=0;i<PROBLEMSIZE;i++) {
66
p0();
67
}
68
}
69
70
void p1l() {
71
int i;
72
for(i=0;i<PROBLEMSIZE;i++) {
73
p1();
74
}
75
}