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 5 6 #include <assert.h> 7 #include <dirent.h> 8 #include <pthread.h> 9 #include <stdlib.h> 10 #include <unistd.h> 11 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; 16 17 // Limit the number of simultaneous threads to avoid reaching the limit. 18 static const size_t kTestThreadsBatch = 100; 19 null_func(void * args)20void *null_func(void *args) { 21 return NULL; 22 } 23 main(void)24int 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); 29 30 for (size_t j = 0; j < kTestThreadsBatch; ++j) 31 assert(pthread_join(thread[j], NULL) == 0); 32 } 33 return 0; 34 } 35