Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / sanitizer_common / TestCases / Posix / create_thread_loop2.cpp
blobfdbc5712d83def462bc53c05ac4601334ce059cd
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
5 // Crashes on Android.
6 // UNSUPPORTED: android
8 #include <cstdint>
9 #include <pthread.h>
10 #include <stdlib.h>
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) {
22 pthread_t thread;
23 if (pthread_create(&thread, 0, null_func, nullptr) == 0)
24 pthread_detach(thread);
26 return nullptr;
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);
38 return 0;