Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / fork_atexit.cpp
blob6e3a2f5c4ba78effa0de765b2441407245cc4610
1 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=50 %run %t 2>&1 | FileCheck %s
2 #include <pthread.h>
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <sys/types.h>
7 #include <sys/wait.h>
9 void foo() {
10 fprintf(stderr, "CHILD ATEXIT\n");
13 void *worker(void *unused) {
14 return 0;
17 int main() {
18 pthread_t t;
19 pthread_create(&t, NULL, worker, NULL);
20 int pid = fork();
21 if (pid == 0) {
22 // child
23 atexit(foo);
24 fprintf(stderr, "CHILD DONE\n");
25 } else {
26 pthread_join(t, 0);
27 if (waitpid(pid, 0, 0) == -1) {
28 perror("waitpid");
29 exit(1);
31 fprintf(stderr, "PARENT DONE\n");
35 // CHECK: CHILD DONE
36 // CHECK: CHILD ATEXIT
37 // CHECK: PARENT DONE