[compiler-rt] 3a1eb1c - [TSan] Make test fail more predictably

Julian Lettner via llvm-commits llvm-commits at lists.llvm.org
Thu Dec 16 08:33:43 PST 2021


Author: Julian Lettner
Date: 2021-12-16T08:33:32-08:00
New Revision: 3a1eb1cf2ae581415cc5750803b082f3676d835c

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

LOG: [TSan] Make test fail more predictably

This test would hang when the system ran out of resources and we fail to
create all 300 threads.

Differential Revision: https://reviews.llvm.org/D115845

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 f1425e823dd3a..172a8c04b1f3d 100644
--- a/compiler-rt/test/tsan/lots_of_threads.c
+++ b/compiler-rt/test/tsan/lots_of_threads.c
@@ -18,8 +18,13 @@ int main() {
   pthread_attr_setstacksize(&attr, 16 << 20);
   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);
+    for (int t = 0; t < kThreads; t++) {
+      int err = pthread_create(&threads[t], &attr, thr, 0);
+      if (err) {
+        fprintf(stderr, "Failed to create thread #%d\n", t);
+        return 1;
+      }
+    }
     barrier_wait(&barrier);
     for (int t = 0; t < kThreads; t++)
       pthread_join(threads[t], 0);


        


More information about the llvm-commits mailing list