| 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s |
|---|---|
| 2 | #include "test.h" |
| 3 | |
| 4 | int Global; |
| 5 | pthread_mutex_t Mutex = PTHREAD_MUTEX_INITIALIZER; |
| 6 | |
| 7 | void *Thread(void *x) { |
| 8 | AnnotateIgnoreSyncBegin(f: 0, l: 0); |
| 9 | pthread_mutex_lock(mutex: &Mutex); |
| 10 | Global++; |
| 11 | pthread_mutex_unlock(mutex: &Mutex); |
| 12 | AnnotateIgnoreSyncEnd(f: 0, l: 0); |
| 13 | return 0; |
| 14 | } |
| 15 | |
| 16 | int main() { |
| 17 | pthread_t t; |
| 18 | pthread_create(newthread: &t, attr: 0, start_routine: Thread, arg: 0); |
| 19 | pthread_mutex_lock(mutex: &Mutex); |
| 20 | Global++; |
| 21 | pthread_mutex_unlock(mutex: &Mutex); |
| 22 | pthread_join(th: t, thread_return: 0); |
| 23 | } |
| 24 | |
| 25 | // CHECK: WARNING: ThreadSanitizer: data race |
| 26 | |
| 27 |
