1 // Test that threads are reused.
2 // On Android, pthread_* are in libc.so. So the `-lpthread` is not supported.
3 // Use `-pthread` so that its driver will DTRT (ie., ignore it).
4 // RUN: %clangxx_lsan %s -o %t -pthread && %run %t
12 // Number of threads to create. This value is greater than kMaxThreads in
13 // lsan_thread.cpp so that we can test that thread contexts are not being
15 static const size_t kTestThreads
= 10000;
17 // Limit the number of simultaneous threads to avoid reaching the limit.
18 static const size_t kTestThreadsBatch
= 100;
20 void *null_func(void *args
) {
25 for (size_t i
= 0; i
< kTestThreads
; i
+= kTestThreadsBatch
) {
26 pthread_t thread
[kTestThreadsBatch
];
27 for (size_t j
= 0; j
< kTestThreadsBatch
; ++j
)
28 assert(pthread_create(&thread
[j
], NULL
, null_func
, NULL
) == 0);
30 for (size_t j
= 0; j
< kTestThreadsBatch
; ++j
)
31 assert(pthread_join(thread
[j
], NULL
) == 0);