Home | History | Annotate | Download | only in lit_tests
      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 extern "C" void AnnotateThreadName(const char *f, int l, const char *name);
      7 
      8 int Global;
      9 
     10 void *Thread1(void *x) {
     11   sleep(1);
     12   AnnotateThreadName(__FILE__, __LINE__, "Thread1");
     13   Global++;
     14   return NULL;
     15 }
     16 
     17 void *Thread2(void *x) {
     18 #if SANITIZER_LINUX && __GLIBC_PREREQ(2, 12)
     19   pthread_setname_np(pthread_self(), "Thread2");
     20 #else
     21   AnnotateThreadName(__FILE__, __LINE__, "Thread2");
     22 #endif
     23   Global--;
     24   return NULL;
     25 }
     26 
     27 int main() {
     28   pthread_t t[2];
     29   pthread_create(&t[0], NULL, Thread1, NULL);
     30   pthread_create(&t[1], NULL, Thread2, NULL);
     31   pthread_join(t[0], NULL);
     32   pthread_join(t[1], NULL);
     33 }
     34 
     35 // CHECK: WARNING: ThreadSanitizer: data race
     36 // CHECK:   Thread T1 'Thread1'
     37 // CHECK:   Thread T2 'Thread2'
     38 
     39