[compiler-rt] bfb597b - tsan: improve lots_of_threads test

Dmitry Vyukov via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 28 08:36:12 PDT 2021


Author: Dmitry Vyukov
Date: 2021-07-28T17:36:06+02:00
New Revision: bfb597b24c311f8a03ad9530adef3b3c1e5ff853

URL: https://github.com/llvm/llvm-project/commit/bfb597b24c311f8a03ad9530adef3b3c1e5ff853
DIFF: https://github.com/llvm/llvm-project/commit/bfb597b24c311f8a03ad9530adef3b3c1e5ff853.diff

LOG: 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

Added: 
    

Modified: 
    compiler-rt/test/tsan/lots_of_threads.c

Removed: 
    


################################################################################
diff  --git a/compiler-rt/test/tsan/lots_of_threads.c b/compiler-rt/test/tsan/lots_of_threads.c
index eef9b1cb036c9..f1425e823dd3a 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;
 }


        


More information about the llvm-commits mailing list