1 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=50 %run %t 2>&1 | FileCheck %s 2 // UNSUPPORTED: darwin 3 #include <pthread.h> 4 #include <stdio.h> 5 #include <stdlib.h> 6 #include <unistd.h> 7 #include <sys/types.h> 8 #include <sys/wait.h> 9 10 void foo() { 11 printf("CHILD ATEXIT\n"); 12 } 13 14 void *worker(void *unused) { 15 return 0; 16 } 17 18 int main() { 19 pthread_t t; 20 pthread_create(&t, NULL, worker, NULL); 21 int pid = fork(); 22 if (pid == 0) { 23 // child 24 atexit(foo); 25 fprintf(stderr, "CHILD DONE\n"); 26 } else { 27 pthread_join(t, 0); 28 if (waitpid(pid, 0, 0) == -1) { 29 perror("waitpid"); 30 exit(1); 31 } 32 fprintf(stderr, "PARENT DONE\n"); 33 } 34 } 35 36 // CHECK: CHILD DONE 37 // CHECK: CHILD ATEXIT 38 // CHECK: PARENT DONE 39