[ASan/Win] Add a comment about DCL-using-static vs threads
[blocksruntime.git] / test / tsan / mutex_robust2.cc
blobf3125c115d66a03ba6ff71e652f2a7a38afffab8
1 // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdlib.h>
4 #include <stdio.h>
5 #include <unistd.h>
6 #include <errno.h>
8 pthread_mutex_t m;
9 int x;
11 void *thr(void *p) {
12 pthread_mutex_lock(&m);
13 x = 42;
14 return 0;
17 int main() {
18 pthread_mutexattr_t a;
19 pthread_mutexattr_init(&a);
20 pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
21 pthread_mutex_init(&m, &a);
22 pthread_t th;
23 pthread_create(&th, 0, thr, 0);
24 sleep(1);
25 if (pthread_mutex_trylock(&m) != EOWNERDEAD) {
26 fprintf(stderr, "not EOWNERDEAD\n");
27 exit(1);
29 x = 43;
30 pthread_join(th, 0);
31 fprintf(stderr, "DONE\n");
34 // This is a false positive, tsan must not bark at the data race.
35 // But currently it does.
36 // CHECK-NOT: WARNING: ThreadSanitizer WARNING: double lock of mutex
37 // CHECK: WARNING: ThreadSanitizer: data race
38 // CHECK-NOT: EOWNERDEAD
39 // CHECK: DONE
40 // CHECK-NOT: WARNING: ThreadSanitizer