Home | History | Annotate | Download | only in tsan
      1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
      2 // Regression test for
      3 // https://code.google.com/p/thread-sanitizer/issues/detail?id=61
      4 // When the data race was reported, pthread_atfork() handler used to be
      5 // executed which caused another race report in the same thread, which resulted
      6 // in a deadlock.
      7 #include <pthread.h>
      8 #include <stdio.h>
      9 #include <unistd.h>
     10 
     11 int glob = 0;
     12 
     13 void *worker(void *unused) {
     14   sleep(1);
     15   glob++;
     16   return NULL;
     17 }
     18 
     19 void atfork() {
     20   fprintf(stderr, "ATFORK\n");
     21   glob++;
     22 }
     23 
     24 int main() {
     25   pthread_atfork(atfork, NULL, NULL);
     26   pthread_t t;
     27   pthread_create(&t, NULL, worker, NULL);
     28   glob++;
     29   pthread_join(t, NULL);
     30   // CHECK: ThreadSanitizer: data race
     31   // CHECK-NOT: ATFORK
     32   return 0;
     33 }
     34