1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
5 // Create a sync object on stack, so there is something to free on thread end.
7 __atomic_fetch_add(&x
, 1, __ATOMIC_SEQ_CST
);
8 barrier_wait(&barrier
);
13 const int kThreads
= 300;
14 const int kIters
= 10;
15 barrier_init(&barrier
, kThreads
+ 1);
17 pthread_attr_init(&attr
);
18 pthread_attr_setstacksize(&attr
, 16 << 20);
19 for (int iter
= 0; iter
< kIters
; iter
++) {
20 pthread_t threads
[kThreads
];
21 for (int t
= 0; t
< kThreads
; t
++) {
22 int err
= pthread_create(&threads
[t
], &attr
, thr
, 0);
24 fprintf(stderr
, "Failed to create thread #%d\n", t
);
28 barrier_wait(&barrier
);
29 for (int t
= 0; t
< kThreads
; t
++)
30 pthread_join(threads
[t
], 0);
32 pthread_attr_destroy(&attr
);
33 fprintf(stderr
, "DONE\n");