aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael de Lang <kingoipo@gmail.com>2021-05-14 12:09:45 +0200
committerMartin Liska <mliska@suse.cz>2021-05-14 12:09:58 +0200
commit80b4ce1a5190ebe764b1009afae57dcef45f92c2 (patch)
tree357f1262929d2e2da8dcf0a174128242b837f043
parentfe108dad32f521c4f924a397f11c63f86519e183 (diff)
downloadgcc-80b4ce1a5190ebe764b1009afae57dcef45f92c2.zip
gcc-80b4ce1a5190ebe764b1009afae57dcef45f92c2.tar.gz
gcc-80b4ce1a5190ebe764b1009afae57dcef45f92c2.tar.bz2
TSAN: add new test
gcc/testsuite/ChangeLog: * g++.dg/tsan/pthread_cond_clockwait.C: New test.
-rw-r--r--gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C31
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C b/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C
new file mode 100644
index 0000000..82d6a5c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/tsan/pthread_cond_clockwait.C
@@ -0,0 +1,31 @@
+// Test pthread_cond_clockwait not generating false positives with tsan
+// { dg-do run { target { { *-*-linux* *-*-gnu* *-*-uclinux* } && pthread } } }
+// { dg-options "-fsanitize=thread -lpthread" }
+
+#include <pthread.h>
+
+pthread_cond_t cv;
+pthread_mutex_t mtx;
+
+void *fn(void *vp) {
+ pthread_mutex_lock(&mtx);
+ pthread_cond_signal(&cv);
+ pthread_mutex_unlock(&mtx);
+ return NULL;
+}
+
+int main() {
+ pthread_mutex_lock(&mtx);
+
+ pthread_t tid;
+ pthread_create(&tid, NULL, fn, NULL);
+
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ ts.tv_sec += 10;
+ pthread_cond_clockwait(&cv, &mtx, CLOCK_MONOTONIC, &ts);
+ pthread_mutex_unlock(&mtx);
+
+ pthread_join(tid, NULL);
+ return 0;
+}