diff options
Diffstat (limited to 'test/tsan/pthread_atfork_deadlock.c')
-rw-r--r-- | test/tsan/pthread_atfork_deadlock.c | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/test/tsan/pthread_atfork_deadlock.c b/test/tsan/pthread_atfork_deadlock.c new file mode 100644 index 000000000000..0f33b9022e5f --- /dev/null +++ b/test/tsan/pthread_atfork_deadlock.c @@ -0,0 +1,33 @@ +// RUN: %clang_tsan -O1 %s -lpthread -o %t && %deflake %run %t | FileCheck %s +// Regression test for +// https://code.google.com/p/thread-sanitizer/issues/detail?id=61 +// When the data race was reported, pthread_atfork() handler used to be +// executed which caused another race report in the same thread, which resulted +// in a deadlock. +#include <pthread.h> +#include <stdio.h> +#include <unistd.h> + +int glob = 0; + +void *worker(void *unused) { + sleep(1); + glob++; + return NULL; +} + +void atfork() { + fprintf(stderr, "ATFORK\n"); + glob++; +} + +int main() { + pthread_atfork(atfork, NULL, NULL); + pthread_t t; + pthread_create(&t, NULL, worker, NULL); + glob++; + pthread_join(t, NULL); + // CHECK: ThreadSanitizer: data race + // CHECK-NOT: ATFORK + return 0; +} |