35 lines · cpp
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 %t5 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 in13// lsan_thread.cpp so that we can test that thread contexts are not being14// reused.15static const size_t kTestThreads = 10000;16 17// Limit the number of simultaneous threads to avoid reaching the limit.18static const size_t kTestThreadsBatch = 100;19 20void *null_func(void *args) {21 return NULL;22}23 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