Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / tsan / lots_of_threads.c
blob172a8c04b1f3d37a1510414bb6c7be0e95d5467e
1 // RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
2 #include "test.h"
4 void *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;
12 int main() {
13 const int kThreads = 300;
14 const int kIters = 10;
15 barrier_init(&barrier, kThreads + 1);
16 pthread_attr_t attr;
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);
23 if (err) {
24 fprintf(stderr, "Failed to create thread #%d\n", t);
25 return 1;
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");
34 return 0;
37 // CHECK: DONE