Skip to content

Commit

Permalink
Avoid stack overflow in task_size bulk test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msimberg committed Nov 19, 2024
1 parent 2df06f7 commit c534201
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions tests/performance/local/task_size.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit c534201

Please sign in to comment.