]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
1 | // RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s |
2 | #include <pthread.h> | |
3 | #include <stdio.h> | |
4 | ||
5 | extern "C" void AnnotateIgnoreSyncBegin(const char*, int); | |
6 | extern "C" void AnnotateIgnoreSyncEnd(const char*, int); | |
7 | ||
8 | int Global; | |
9 | pthread_mutex_t Mutex = PTHREAD_MUTEX_INITIALIZER; | |
10 | ||
11 | void *Thread(void *x) { | |
12 | AnnotateIgnoreSyncBegin(0, 0); | |
13 | pthread_mutex_lock(&Mutex); | |
14 | Global++; | |
15 | pthread_mutex_unlock(&Mutex); | |
16 | AnnotateIgnoreSyncEnd(0, 0); | |
17 | return 0; | |
18 | } | |
19 | ||
20 | int main() { | |
21 | pthread_t t; | |
22 | pthread_create(&t, 0, Thread, 0); | |
23 | pthread_mutex_lock(&Mutex); | |
24 | Global++; | |
25 | pthread_mutex_unlock(&Mutex); | |
26 | pthread_join(t, 0); | |
27 | } | |
28 | ||
29 | // CHECK: WARNING: ThreadSanitizer: data race | |
30 |