From c53420116a07dd64ff1ff0dc3af06fc9c36a768c Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Fri, 15 Nov 2024 17:01:51 +0100 Subject: [PATCH] Avoid stack overflow in task_size bulk test stdexec in debug mode is particularly prone to triggering a stack overflow, but pika's std::execution implementation can trigger it as well. Compiling with optimizations also simply delays the stack overflow. --- tests/performance/local/task_size.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/performance/local/task_size.cpp b/tests/performance/local/task_size.cpp index 7204bb5e3..645a14105 100644 --- a/tests/performance/local/task_size.cpp +++ b/tests/performance/local/task_size.cpp @@ -190,6 +190,12 @@ double do_work_bulk( for (std::uint64_t i = 0; i < tasks_per_thread; ++i) { sender = std::move(sender) | ex::continues_on(sched) | ex::bulk(num_threads, work); + // To avoid stack overflow when connecting, starting, or destroying the operation state, + // eagerly start the chain of work periodically using ensure_started. The chosen frequency + // is mostly arbitrary. It's done as often as reasonably possible to make the probability of + // a stack overflow very low, but not often enough to introduce significant overhead. 100 + // seems like a good compromise. + if (i % 100 == 0) { sender = ex::ensure_started(std::move(sender)); } } double const spawn_time_s = timer.elapsed();