xref: /llvm-project/compiler-rt/test/sanitizer_common/TestCases/Posix/create_thread_loop.cpp (revision 97fd8d264af5a9e95279e50dac936f515dce7d42)
1 // Simple stress test for of pthread_create. Increase arg to use as benchmark.
2 
3 // RUN: %clangxx -O3 -pthread %s -o %t && %run %t 1000
4 
5 // Inconsistently fails on Android and can timeout on darwin platforms.
6 // UNSUPPORTED: android, darwin
7 
8 #include <pthread.h>
9 #include <stdlib.h>
10 
__asan_default_options()11 extern "C" const char *__asan_default_options() {
12   // 32bit asan can allocate just a few FakeStacks.
13   return sizeof(void *) < 8 ? "detect_stack_use_after_return=0" : "";
14 }
15 
null_func(void * args)16 static void *null_func(void *args) { return nullptr; }
17 
main(int argc,char ** argv)18 int main(int argc, char **argv) {
19   int n = atoi(argv[1]);
20   for (int i = 0; i < n; ++i) {
21     pthread_t thread;
22     if (pthread_create(&thread, 0, null_func, NULL) == 0)
23       pthread_detach(thread);
24   }
25   return 0;
26 }
27