[LLDB][LLDB-DAP] Wire up DAP to listen to external progress events (#123826)
[llvm-project.git] / compiler-rt / test / tsan / Linux / fork_syscall.cpp
blob5764cd14c87f07502fccb71150b0e4cdb0ec4b1a
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>
8 int counter;
10 static void *incrementer(void *p) {
11 for (;;)
12 __sync_fetch_and_add(&counter, 1);
13 return 0;
16 int main() {
17 pthread_t th1;
18 pthread_create(&th1, 0, incrementer, 0);
19 for (int i = 0; i < 10; i++) {
20 switch (myfork()) {
21 default: // parent
22 while (wait(0) < 0) {
24 fprintf(stderr, ".");
25 break;
26 case 0: // child
27 __sync_fetch_and_add(&counter, 1);
28 exit(0);
29 break;
30 case -1: // error
31 fprintf(stderr, "failed to fork (%d)\n", errno);
32 exit(1);
35 fprintf(stderr, "OK\n");
38 // CHECK: OK