From bfb597b24c311f8a03ad9530adef3b3c1e5ff853 Mon Sep 17 00:00:00 2001 From: Dmitry Vyukov Date: Wed, 28 Jul 2021 15:00:00 +0200 Subject: [PATCH] tsan: improve lots_of_threads test The current 10 threads is not particularly "lots" and not stressful. Create 10x300 threads and ensure they all are running at the same time. Depends on D106953. Reviewed By: melver Differential Revision: https://reviews.llvm.org/D106954 --- compiler-rt/test/tsan/lots_of_threads.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/compiler-rt/test/tsan/lots_of_threads.c b/compiler-rt/test/tsan/lots_of_threads.c index eef9b1cb036c..f1425e823dd3 100644 --- a/compiler-rt/test/tsan/lots_of_threads.c +++ b/compiler-rt/test/tsan/lots_of_threads.c @@ -10,18 +10,21 @@ void *thr(void *arg) { } int main() { - const int kThreads = 10; + const int kThreads = 300; + const int kIters = 10; barrier_init(&barrier, kThreads + 1); - pthread_t t[kThreads]; pthread_attr_t attr; pthread_attr_init(&attr); pthread_attr_setstacksize(&attr, 16 << 20); - pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); - for (int i = 0; i < kThreads; i++) - pthread_create(&t[i], &attr, thr, 0); + for (int iter = 0; iter < kIters; iter++) { + pthread_t threads[kThreads]; + for (int t = 0; t < kThreads; t++) + pthread_create(&threads[t], &attr, thr, 0); + barrier_wait(&barrier); + for (int t = 0; t < kThreads; t++) + pthread_join(threads[t], 0); + } pthread_attr_destroy(&attr); - barrier_wait(&barrier); - sleep(1); fprintf(stderr, "DONE\n"); return 0; }