Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 2 | // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=die_after_fork=0 %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE |
| 3 | // UNSUPPORTED: darwin |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 4 | #include "test.h" |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 5 | #include <errno.h> |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 6 | #include <sys/types.h> |
| 7 | #include <sys/wait.h> |
| 8 | |
| 9 | static void *sleeper(void *p) { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 10 | sleep(10); // not intended to exit during test |
| 11 | return 0; |
| 12 | } |
| 13 | |
| 14 | static void *nop(void *p) { |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 15 | return 0; |
| 16 | } |
| 17 | |
| 18 | int main() { |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 19 | barrier_init(&barrier, 2); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 20 | pthread_t th; |
| 21 | pthread_create(&th, 0, sleeper, 0); |
| 22 | switch (fork()) { |
| 23 | default: // parent |
| 24 | while (wait(0) < 0) {} |
| 25 | break; |
| 26 | case 0: // child |
| 27 | { |
| 28 | pthread_t th2; |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 29 | pthread_create(&th2, 0, nop, 0); |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 30 | exit(0); |
| 31 | break; |
| 32 | } |
| 33 | case -1: // error |
| 34 | fprintf(stderr, "failed to fork (%d)\n", errno); |
| 35 | exit(1); |
| 36 | } |
| 37 | fprintf(stderr, "OK\n"); |
| 38 | } |
| 39 | |
| 40 | // CHECK-DIE: ThreadSanitizer: starting new threads after multi-threaded fork is not supported |
| 41 | // CHECK-DIE: OK |
| 42 | |
| 43 | // CHECK-NODIE-NOT: ThreadSanitizer: starting new threads after multi-threaded fork is not supported |
| 44 | // CHECK-NODIE: OK |
| 45 | |