Skip to content

Commit b8678a4

Browse files
authored
Merge pull request diffblue#4271 from tautschnig/pthread_cond_wait
pthread_cond_wait may return spuriously
2 parents e50449d + 4c6a9fc commit b8678a4

File tree

31 files changed

+79
-38
lines changed

31 files changed

+79
-38
lines changed
+10
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
if(NOT WIN32)
12
add_test_pl_tests(
23
"$<TARGET_FILE:cbmc>"
34
)
5+
else()
6+
add_test_pl_tests(
7+
"$<TARGET_FILE:cbmc>"
8+
"cbmc-library"
9+
"$<TARGET_FILE:cbmc>"
10+
"-C;-X;pthread"
11+
"CORE"
12+
)
13+
endif()

regression/cbmc-library/Makefile

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
11
default: tests.log
22

3+
include ../../src/config.inc
4+
include ../../src/common
5+
6+
ifeq ($(BUILD_ENV_),MSVC)
7+
no_pthread = -X pthread
8+
endif
9+
310
test:
4-
@../test.pl -e -p -c ../../../src/cbmc/cbmc
11+
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(no_pthread)
512

613
tests.log: ../test.pl
7-
@../test.pl -e -p -c ../../../src/cbmc/cbmc
14+
@../test.pl -e -p -c ../../../src/cbmc/cbmc $(no_pthread)
815

916
show:
1017
@for dir in *; do \

regression/cbmc-library/pthread_barrier_destroy-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_barrier_init-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_barrier_wait-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_cancel-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_cond_broadcast-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_cond_init-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_cond_signal-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,32 @@
11
#include <assert.h>
2-
#include <pthread_lib.h>
2+
#include <pthread.h>
3+
4+
pthread_mutex_t lock;
5+
pthread_cond_t cond;
6+
7+
// only accessed in critical section guarded by mutex, so there is no need to
8+
// make this variable atomic or volatile
9+
int x;
10+
11+
void *thread(void *arg)
12+
{
13+
(void)arg;
14+
pthread_mutex_lock(&lock);
15+
pthread_cond_wait(&cond, &lock);
16+
// may fail: pthread_cond_wait can be waken up spuriously (see man
17+
// pthread_cond_wait)
18+
assert(x == 1);
19+
pthread_mutex_unlock(&lock);
20+
return NULL;
21+
}
322

423
int main()
524
{
6-
pthread_cond_wait();
7-
assert(0);
8-
return 0;
25+
pthread_t t;
26+
pthread_mutex_init(&lock, 0);
27+
pthread_cond_init(&cond, 0);
28+
pthread_create(&t, NULL, thread, NULL);
29+
x = 1;
30+
pthread_cond_broadcast(&cond);
31+
pthread_join(t, NULL);
932
}
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
KNOWNBUG
1+
CORE pthread
22
main.c
3-
--pointer-check --bounds-check
4-
^EXIT=0$
3+
--bounds-check
4+
^EXIT=10$
55
^SIGNAL=0$
6-
^VERIFICATION SUCCESSFUL$
6+
^\*\* 1 of 2 failed
7+
^VERIFICATION FAILED$
78
--
89
^warning: ignoring

regression/cbmc-library/pthread_create-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_exit-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_join-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_mutex_destroy-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_mutex_init-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_mutex_lock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_mutex_trylock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_mutex_unlock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_mutexattr_settype-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_rwlock_destroy-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_rwlock_init-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_rwlock_rdlock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_rwlock_tryrdlock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_rwlock_trywrlock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_rwlock_unlock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_rwlock_wrlock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_spin_lock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_spin_trylock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

regression/cbmc-library/pthread_spin_unlock-01/test.desc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
KNOWNBUG
1+
KNOWNBUG pthread
22
main.c
33
--pointer-check --bounds-check
44
^EXIT=0$

src/ansi-c/library/pthread_lib.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -636,8 +636,8 @@ inline int pthread_cond_wait(
636636
#endif
637637

638638
__CPROVER_atomic_begin();
639-
__CPROVER_assume(*((unsigned *)cond));
640-
(*((unsigned *)cond))--;
639+
if(*((unsigned *)cond))
640+
(*((unsigned *)cond))--;
641641
__CPROVER_atomic_end();
642642

643643
return 0; // we never fail

0 commit comments

Comments
 (0)