1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
---|---|
2 | #include <pthread.h> |
3 | #include <stdlib.h> |
4 | #include <stdio.h> |
5 | #include <unistd.h> |
6 | #include <errno.h> |
7 | |
8 | pthread_mutex_t m; |
9 | int x; |
10 | |
11 | void *thr(void *p) { |
12 | pthread_mutex_lock(mutex: &m); |
13 | x = 42; |
14 | return 0; |
15 | } |
16 | |
17 | int main() { |
18 | pthread_mutexattr_t a; |
19 | pthread_mutexattr_init(attr: &a); |
20 | pthread_mutexattr_setrobust(attr: &a, robustness: PTHREAD_MUTEX_ROBUST); |
21 | pthread_mutex_init(mutex: &m, mutexattr: &a); |
22 | pthread_t th; |
23 | pthread_create(newthread: &th, attr: 0, start_routine: thr, arg: 0); |
24 | sleep(seconds: 1); |
25 | if (pthread_mutex_trylock(mutex: &m) != EOWNERDEAD) { |
26 | fprintf(stderr, format: "not EOWNERDEAD\n"); |
27 | exit(status: 1); |
28 | } |
29 | x = 43; |
30 | pthread_join(th: th, thread_return: 0); |
31 | fprintf(stderr, format: "DONE\n"); |
32 | } |
33 | |
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 |
41 | |
42 |