Home | History | Annotate | Download | only in tsan
      1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE
      2 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=die_after_fork=0 %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE
      3 // UNSUPPORTED: darwin
      4 #include "test.h"
      5 #include <errno.h>
      6 #include <sys/types.h>
      7 #include <sys/wait.h>
      8 
      9 static void *sleeper(void *p) {
     10   sleep(10);  // not intended to exit during test
     11   return 0;
     12 }
     13 
     14 static void *nop(void *p) {
     15   return 0;
     16 }
     17 
     18 int main() {
     19   barrier_init(&barrier, 2);
     20   pthread_t th;
     21   pthread_create(&th, 0, sleeper, 0);
     22   switch (fork()) {
     23   default:  // parent
     24     while (wait(0) < 0) {}
     25     break;
     26   case 0:  // child
     27     {
     28       pthread_t th2;
     29       pthread_create(&th2, 0, nop, 0);
     30       exit(0);
     31       break;
     32     }
     33   case -1:  // error
     34     fprintf(stderr, "failed to fork (%d)\n", errno);
     35     exit(1);
     36   }
     37   fprintf(stderr, "OK\n");
     38 }
     39 
     40 // CHECK-DIE: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
     41 // CHECK-DIE: OK
     42 
     43 // CHECK-NODIE-NOT: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
     44 // CHECK-NODIE: OK
     45 
     46