1// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=50 %run %t 2>&1 | FileCheck %s
2#include "../test.h"
3#include "syscall.h"
4#include <errno.h>
5#include <sys/types.h>
6#include <sys/wait.h>
7
8int counter;
9
10static void *incrementer(void *p) {
11 for (;;)
12 __sync_fetch_and_add(&counter, 1);
13 return 0;
14}
15
16int main() {
17 pthread_t th1;
18 pthread_create(newthread: &th1, attr: 0, start_routine: incrementer, arg: 0);
19 for (int i = 0; i < 10; i++) {
20 switch (myfork()) {
21 default: // parent
22 while (wait(stat_loc: 0) < 0) {
23 }
24 fprintf(stderr, format: ".");
25 break;
26 case 0: // child
27 __sync_fetch_and_add(&counter, 1);
28 exit(status: 0);
29 break;
30 case -1: // error
31 fprintf(stderr, format: "failed to fork (%d)\n", errno);
32 exit(status: 1);
33 }
34 }
35 fprintf(stderr, format: "OK\n");
36}
37
38// CHECK: OK
39

source code of compiler-rt/test/tsan/Linux/fork_syscall.cpp