1// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2#include "test.h"
3
4void *thr(void *arg) {
5 // Create a sync object on stack, so there is something to free on thread end.
6 volatile int x;
7 __atomic_fetch_add(&x, 1, __ATOMIC_SEQ_CST);
8 barrier_wait(&barrier);
9 return 0;
10}
11
12int main() {
13 const int kThreads = 10;
14 barrier_init(&barrier, kThreads + 1);
15 pthread_t t[kThreads];
16 pthread_attr_t attr;
17 pthread_attr_init(&attr);
18 pthread_attr_setstacksize(&attr, 16 << 20);
19 pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
20 for (int i = 0; i < kThreads; i++)
21 pthread_create(&t[i], &attr, thr, 0);
22 pthread_attr_destroy(&attr);
23 barrier_wait(&barrier);
24 sleep(1);
25 fprintf(stderr, "DONE\n");
26 return 0;
27}
28
29// CHECK: DONE
30
31