Skip to content

Allow suspended threads migration to another arena in case of tasks absence. #1909

@kboyarinov

Description

@kboyarinov

Summary

Follow up for #1822

According to oneTBB specification, threads suspended by tbb::task::suspend are participating in other TBB work. But in fact the suspended thread is bound to the arena where it was suspended.

Consider the following test:
std::size_t concurrency = std::thread::hardware_concurrency();

tbb::task_arena arena_bg(tbb::task_arena::automatic);
tbb::task_arena arena_fg(tbb::task_arena::automatic);

spin_barrier barrier(concurrency);

auto job = [&] {
    arena_fg.execute([&] {
        barrier.wait();

        tbb::task_arena::suspend([&](tbb::suspend_point sp) {
            arena_bg.enqueue([&] {
                tbb::task::resume(sp);
            });
        });
    });
};

tbb::task_group tg;
for (std::size_t i = 0; i < concurrency; ++i) {
    tg.run(job);
}
tg.wait();

Because of the barrier, all available worker threads will join he arena_fg and all of them will be suspended in arena_fg and no workers will come to arena_bg to execute the "resuming" tasks that were enqueued from the suspend functor.

Version

oneTBB 2022.3.0

Observed Behavior

The test case above hangs.

Expected Behavior

The test case above should exit successfully. To achieve this, the suspended threads should be allowed to execute tasks from other arenas.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions