1 // Simple stress test for of pthread_create. Increase arg to use as benchmark.
3 // RUN: %clangxx -O3 -pthread %s -o %t && %run %t 10
6 // UNSUPPORTED: android
12 extern "C" const char *__asan_default_options() {
13 // 32bit asan can allocate just a few FakeStacks.
14 return sizeof(void *) < 8 ? "detect_stack_use_after_return=0" : "";
17 static void *null_func(void *args
) { return nullptr; }
19 static void *loop(void *args
) {
20 uintptr_t n
= (uintptr_t)args
;
21 for (int i
= 0; i
< n
; ++i
) {
23 if (pthread_create(&thread
, 0, null_func
, nullptr) == 0)
24 pthread_detach(thread
);
29 int main(int argc
, char **argv
) {
30 uintptr_t n
= atoi(argv
[1]);
31 pthread_t threads
[64];
32 for (auto &thread
: threads
)
33 while (pthread_create(&thread
, 0, loop
, (void *)n
) != 0) {
36 for (auto &thread
: threads
)
37 pthread_join(thread
, nullptr);