1 // RUN: %clangxx_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2 #include <pthread.h> 3 #include <stdio.h> 4 #include <unistd.h> 5 6 int Global; 7 __thread int huge[1024*1024]; 8 Thread1(void * x)9void *Thread1(void *x) { 10 sleep(1); 11 Global++; 12 return NULL; 13 } 14 Thread2(void * x)15void *Thread2(void *x) { 16 pthread_mutex_t mtx; 17 pthread_mutex_init(&mtx, 0); 18 pthread_mutex_lock(&mtx); 19 Global--; 20 pthread_mutex_unlock(&mtx); 21 pthread_mutex_destroy(&mtx); 22 return NULL; 23 } 24 main()25int main() { 26 pthread_t t[2]; 27 pthread_create(&t[0], NULL, Thread1, NULL); 28 pthread_create(&t[1], NULL, Thread2, NULL); 29 pthread_join(t[0], NULL); 30 pthread_join(t[1], NULL); 31 } 32 33 // CHECK: WARNING: ThreadSanitizer: data race 34 // CHECK: Write of size 4 at {{.*}} by thread T1: 35 // CHECK: Previous write of size 4 at {{.*}} by thread T2 36 // CHECK: (mutexes: write [[M1:M[0-9]+]]): 37 // CHECK: Mutex [[M1]] is already destroyed 38 // CHECK-NOT: Mutex {{.*}} created at 39 40