1 // RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
3 // https://groups.google.com/d/msg/thread-sanitizer/e_zB9gYqFHM/DmAiTsrLAwAJ
4 // pthread_atfork() callback triggers a data race and we deadlocked
5 // on the report_mtx as we lock it around fork.
13 void *worker(void *unused
) {
15 barrier_wait(&barrier
);
24 barrier_init(&barrier
, 2);
25 pthread_atfork(atfork
, atfork
, atfork
);
27 pthread_create(&t
, NULL
, worker
, NULL
);
28 barrier_wait(&barrier
);
31 fprintf(stderr
, "fork failed: %d\n", errno
);
35 fprintf(stderr
, "CHILD\n");
38 if (pid
!= waitpid(pid
, NULL
, 0)) {
39 fprintf(stderr
, "waitpid failed: %d\n", errno
);
42 pthread_join(t
, NULL
);
43 fprintf(stderr
, "PARENT\n");
47 // CHECK: ThreadSanitizer: data race
48 // CHECK: Write of size 4
50 // CHECK: Previous write of size 4