2014-05-01 05:34:17 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE
|
2015-11-20 01:28:46 +08:00
|
|
|
// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=die_after_fork=0 %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE
|
2015-11-07 22:29:38 +08:00
|
|
|
// UNSUPPORTED: darwin
|
2015-01-21 21:50:02 +08:00
|
|
|
#include "test.h"
|
2014-01-24 20:33:35 +08:00
|
|
|
#include <errno.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
static void *sleeper(void *p) {
|
2015-01-21 21:50:02 +08:00
|
|
|
sleep(10); // not intended to exit during test
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void *nop(void *p) {
|
2014-01-24 20:33:35 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main() {
|
2015-01-21 21:50:02 +08:00
|
|
|
barrier_init(&barrier, 2);
|
2014-01-24 20:33:35 +08:00
|
|
|
pthread_t th;
|
|
|
|
pthread_create(&th, 0, sleeper, 0);
|
|
|
|
switch (fork()) {
|
|
|
|
default: // parent
|
|
|
|
while (wait(0) < 0) {}
|
|
|
|
break;
|
|
|
|
case 0: // child
|
|
|
|
{
|
|
|
|
pthread_t th2;
|
2015-01-21 21:50:02 +08:00
|
|
|
pthread_create(&th2, 0, nop, 0);
|
2014-01-24 20:33:35 +08:00
|
|
|
exit(0);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case -1: // error
|
|
|
|
fprintf(stderr, "failed to fork (%d)\n", errno);
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
fprintf(stderr, "OK\n");
|
|
|
|
}
|
|
|
|
|
2014-03-31 18:51:13 +08:00
|
|
|
// CHECK-DIE: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
|
2014-01-24 20:33:35 +08:00
|
|
|
// CHECK-DIE: OK
|
|
|
|
|
2014-03-31 18:51:13 +08:00
|
|
|
// CHECK-NODIE-NOT: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
|
2014-01-24 20:33:35 +08:00
|
|
|
// CHECK-NODIE: OK
|
|
|
|
|