[docs] Fix build-docs.sh
[llvm-project.git] / compiler-rt / test / lsan / TestCases / many_threads_detach.cpp
blobe004dfeff3d8ede3207237870b692fb82ee88be7
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
6 #include <assert.h>
7 #include <dirent.h>
8 #include <pthread.h>
9 #include <stdlib.h>
10 #include <unistd.h>
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
14 // reused.
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) {
21 return NULL;
24 int main(void) {
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);
33 return 0;