Remove check for Android in Mips.cpp (#123793)
[llvm-project.git] / compiler-rt / test / tsan / Linux / clone_deadlock.cpp
blob70846da7d10ad456b2455e59e1854cd24e0b2124
1 // RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=0 %run %t 2>&1 | FileCheck %s
2 #include "../test.h"
3 #include <errno.h>
4 #include <sched.h>
5 #include <sys/types.h>
6 #include <sys/wait.h>
8 long counter;
10 static void *incrementer(void *arg) {
11 for (;;)
12 __sync_fetch_and_add(&counter, 1);
13 return 0;
16 static int cloned(void *arg) {
17 for (int i = 0; i < 1000; i++)
18 __sync_fetch_and_add(&counter, 1);
19 exit(0);
20 return 0;
23 int main() {
24 barrier_init(&barrier, 2);
25 pthread_t th;
26 pthread_create(&th, 0, incrementer, 0);
27 for (int i = 0; i < 100; i++) {
28 char stack[64 << 10] __attribute__((aligned(64)));
29 int pid = clone(cloned, stack + sizeof(stack), SIGCHLD, 0);
30 if (pid == -1) {
31 fprintf(stderr, "failed to clone: %d\n", errno);
32 exit(1);
34 while (wait(0) != pid) {
37 fprintf(stderr, "DONE\n");
40 // CHECK: DONE