1 // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 #include <pthread.h> 3 #include <unistd.h> 4 5 int Global; 6 7 void *Thread1(void *x) { 8 sleep(1); 9 __atomic_fetch_add(&Global, 1, __ATOMIC_RELAXED); 10 return NULL; 11 } 12 13 void *Thread2(void *x) { 14 Global++; 15 return NULL; 16 } 17 18 int main() { 19 pthread_t t[2]; 20 pthread_create(&t[0], NULL, Thread1, NULL); 21 pthread_create(&t[1], NULL, Thread2, NULL); 22 pthread_join(t[0], NULL); 23 pthread_join(t[1], NULL); 24 } 25 26 // CHECK: WARNING: ThreadSanitizer: data race 27 // CHECK: Atomic write of size 4 28 // CHECK: #0 __tsan_atomic32_fetch_add 29 // CHECK: #1 Thread1 30