1 // Stress test for https://reviews.llvm.org/D101881
2 // RUN: %clangxx_hwasan -DREUSE=0 %s -pthread -O2 -o %t && %run %t 2>&1
3 // RUN: %clangxx_hwasan -DREUSE=1 %s -pthread -O2 -o %t_reuse && %run %t_reuse 2>&1
14 constexpr int kTopThreads
= 20;
15 constexpr int kChildThreads
= 30;
16 constexpr int kChildIterations
= REUSE
? 8 : 1;
18 constexpr int kProcessIterations
= 20;
21 for (int i
= 0; i
< kChildIterations
; ++i
) {
22 std::vector
<std::thread
> threads
;
23 threads
.reserve(kChildThreads
);
24 for (int i
= 0; i
< kChildThreads
; ++i
)
25 threads
.emplace_back([]() {});
26 for (auto &t
: threads
)
32 std::vector
<std::thread
> threads
;
33 threads
.reserve(kTopThreads
);
34 for (int i
= 0; i
< kTopThreads
; ++i
)
35 threads
.emplace_back(Thread
);
36 for (auto &t
: threads
)
42 // Test thread reuse with multiple iterations of thread create / join in a single process.
45 // Test new, non-reused thread creation by running a single iteration of create / join in a freshly started process.
46 for (int i
= 0; i
< kProcessIterations
; ++i
) {
51 waitpid(pid
, &wstatus
, 0);
52 } while (!WIFEXITED(wstatus
) && !WIFSIGNALED(wstatus
));
53 if (!WIFEXITED(wstatus
) || WEXITSTATUS(wstatus
)) {
54 fprintf(stderr
, "failed at iteration %d / %d\n", i
, kProcessIterations
);