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 | |
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 | |
16 | static void *null_func(void *args) { return nullptr; } |
17 | |
18 | int main(int argc, char **argv) { |
19 | int n = atoi(nptr: argv[1]); |
20 | for (int i = 0; i < n; ++i) { |
21 | pthread_t thread; |
22 | if (pthread_create(newthread: &thread, attr: 0, start_routine: null_func, NULL) == 0) |
23 | pthread_detach(th: thread); |
24 | } |
25 | return 0; |
26 | } |
27 | |