Skip to content
This repository was archived by the owner on Oct 3, 2021. It is now read-only.

Commit eed2127

Browse files
fixed one more data race
1 parent 9f6e36f commit eed2127

File tree

2 files changed

+37
-7
lines changed

2 files changed

+37
-7
lines changed

c/pthread-lit/qw2004-2.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,18 @@ volatile int stoppingEvent;
1111
volatile int stopped;
1212

1313
int BCSP_IoIncrement() {
14-
if (stoppingFlag) {
14+
__VERIFIER_atomic_begin();
15+
int lsf = stoppingFlag;
16+
__VERIFIER_atomic_end();
17+
if (lsf) {
1518
return -1;
1619
} else {
17-
pendingIo = pendingIo + 1;
20+
__VERIFIER_atomic_begin();
21+
int lp = pendingIo;
22+
__VERIFIER_atomic_end();
23+
__VERIFIER_atomic_begin();
24+
pendingIo = lp + 1;
25+
__VERIFIER_atomic_end();
1826
}
1927
return 0;
2028
}
@@ -31,7 +39,9 @@ void BCSP_IoDecrement() {
3139
int pending;
3240
pending = dec();
3341
if (pending == 0) {
42+
__VERIFIER_atomic_begin();
3443
stoppingEvent = 1;
44+
__VERIFIER_atomic_end();
3545
}
3646
}
3747

@@ -46,9 +56,14 @@ void* BCSP_PnpAdd(void* arg) {
4656
}
4757

4858
void* BCSP_PnpStop(void* arg) {
59+
__VERIFIER_atomic_begin();
4960
stoppingFlag = 1;
61+
__VERIFIER_atomic_end();
5062
BCSP_IoDecrement();
51-
assume_abort_if_not(stoppingEvent);
63+
__VERIFIER_atomic_begin();
64+
int lse = stoppingEvent;
65+
__VERIFIER_atomic_end();
66+
assume_abort_if_not(lse);
5267
stopped = 1;
5368
return 0;
5469
}

c/pthread-lit/qw2004-2.i

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -699,10 +699,18 @@ volatile int pendingIo;
699699
volatile int stoppingEvent;
700700
volatile int stopped;
701701
int BCSP_IoIncrement() {
702-
if (stoppingFlag) {
702+
__VERIFIER_atomic_begin();
703+
int lsf = stoppingFlag;
704+
__VERIFIER_atomic_end();
705+
if (lsf) {
703706
return -1;
704707
} else {
705-
pendingIo = pendingIo + 1;
708+
__VERIFIER_atomic_begin();
709+
int lp = pendingIo;
710+
__VERIFIER_atomic_end();
711+
__VERIFIER_atomic_begin();
712+
pendingIo = lp + 1;
713+
__VERIFIER_atomic_end();
706714
}
707715
return 0;
708716
}
@@ -717,7 +725,9 @@ void BCSP_IoDecrement() {
717725
int pending;
718726
pending = dec();
719727
if (pending == 0) {
720-
stoppingEvent = 1;
728+
__VERIFIER_atomic_begin();
729+
stoppingEvent = 1;
730+
__VERIFIER_atomic_end();
721731
}
722732
}
723733
void* BCSP_PnpAdd(void* arg) {
@@ -730,9 +740,14 @@ void* BCSP_PnpAdd(void* arg) {
730740
return 0;
731741
}
732742
void* BCSP_PnpStop(void* arg) {
743+
__VERIFIER_atomic_begin();
733744
stoppingFlag = 1;
745+
__VERIFIER_atomic_end();
734746
BCSP_IoDecrement();
735-
assume_abort_if_not(stoppingEvent);
747+
__VERIFIER_atomic_begin();
748+
int lse = stoppingEvent;
749+
__VERIFIER_atomic_end();
750+
assume_abort_if_not(lse);
736751
stopped = 1;
737752
return 0;
738753
}

0 commit comments

Comments
 (0)