1 // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
3 // The test tries to provoke internal allocator to be locked during fork
4 // and then force the child process to use the internal allocator.
11 static void *forker(void *arg
) {
12 void *p
= calloc(1, 16);
13 static_cast<volatile int *>(p
)[0]++;
14 __atomic_fetch_add(static_cast<int *>(p
), 1, __ATOMIC_SEQ_CST
);
17 fprintf(stderr
, "failed to fork (%d)\n", errno
);
21 __atomic_fetch_add(&static_cast<int *>(p
)[1], 1, __ATOMIC_SEQ_CST
);
25 while (waitpid(pid
, &status
, 0) != pid
) {
27 if (!WIFEXITED(status
) || WEXITSTATUS(status
) != 0) {
28 fprintf(stderr
, "subprocess failed (%d)\n", status
);
36 for (int i
= 0; i
< 10; i
++) {
37 pthread_t threads
[100];
38 for (auto &th
: threads
)
39 pthread_create(&th
, 0, forker
, 0);
40 for (auto th
: threads
)
43 fprintf(stderr
, "DONE\n");