1 // TODO(#96597): fix and reenable
4 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=0 %run %t 2>&1 | FileCheck %s
6 // This test models what happens on Mac when fork
7 // calls malloc/free inside of our atfork callbacks.
8 // and ensures that we don't deadlock on malloc/free calls.
14 #include <sys/types.h>
17 // disable_sanitizer_instrumentation on __tsan_test_only_on_fork is not
18 // transitive, so we must apply it here as well.
19 // Instrumenting alloc_free_blocks() will result in deadlocks in TSan.
20 __attribute__((disable_sanitizer_instrumentation
)) void alloc_free_blocks() {
21 // Allocate a bunch of blocks to drain local allocator cache
22 // and provoke it to lock allocator global mutexes.
23 const int kBlocks
= 1000;
24 void *blocks
[kBlocks
];
25 for (int i
= 0; i
< kBlocks
; i
++) {
27 *(volatile char *)p
= 0;
30 for (int i
= 0; i
< kBlocks
; i
++)
34 __attribute__((disable_sanitizer_instrumentation
)) extern "C" void
35 __tsan_test_only_on_fork() {
36 const char *msg
= "__tsan_test_only_on_fork\n";
37 write(2, msg
, strlen(msg
));
41 static void *background(void *p
) {
49 pthread_create(&th
, 0, background
, 0);
51 for (int i
= 0; i
< 10; i
++) {
54 fprintf(stderr
, "failed to fork (%d)\n", errno
);
65 fprintf(stderr
, "DONE\n");
68 // CHECK: __tsan_test_only_on_fork