Files
clang-p2996/compiler-rt/test/tsan/fork_multithreaded3.cc
Kuba Brecka 3bab18d4af [tsan] Fix fork() and fork-based tests for OS X
On OS X, fork() under TSan asserts (in debug builds only) because REAL(fork) calls some intercepted functions, which check that no internal locks are held via CheckNoLocks(). But the wrapper of fork intentionally holds some locks. This patch fixes that by using ScopedIgnoreInterceptors during the call to REAL(fork). After that, all the fork-based tests seem to pass on OS X, so let's just remove all the UNSUPPORTED: darwin annotations we have.

Differential Revision: http://reviews.llvm.org/D18409

llvm-svn: 264261
2016-03-24 11:54:33 +00:00

41 lines
781 B
C++

// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <pthread.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
static void *racer(void *p) {
*(int*)p = 42;
return 0;
}
int main() {
switch (fork()) {
default: // parent
while (wait(0) < 0) {}
break;
case 0: // child
{
int x = 0;
pthread_t th1, th2;
pthread_create(&th1, 0, racer, &x);
pthread_create(&th2, 0, racer, &x);
pthread_join(th1, 0);
pthread_join(th2, 0);
exit(0);
break;
}
case -1: // error
fprintf(stderr, "failed to fork (%d)\n", errno);
exit(1);
}
fprintf(stderr, "OK\n");
}
// CHECK: ThreadSanitizer: data race
// CHECK: OK