1// RUN: %clang_tsan -O1 %s -o %t && not %t 2>&1 | FileCheck %s 2#include <pthread.h> 3#include <stdio.h> 4#include <stddef.h> 5#include <unistd.h> 6 7pthread_barrier_t B; 8int Global; 9 10void *Thread1(void *x) { 11 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD) 12 pthread_barrier_destroy(&B); 13 return NULL; 14} 15 16void *Thread2(void *x) { 17 if (pthread_barrier_wait(&B) == PTHREAD_BARRIER_SERIAL_THREAD) 18 pthread_barrier_destroy(&B); 19 return NULL; 20} 21 22int main() { 23 pthread_barrier_init(&B, 0, 2); 24 pthread_t t; 25 pthread_create(&t, NULL, Thread1, NULL); 26 Thread2(0); 27 pthread_join(t, NULL); 28 return 0; 29} 30 31// CHECK: WARNING: ThreadSanitizer: data race 32