Skip to content

Behavior of resumable tasks and task arenas #1822

@CCT825

Description

@CCT825

Hi,

I have encountered a problem with version 2022.2.0 (and older) when using resumable tasks that task arenas were not getting any worker threads.
I have boiled it down to the following reproducer:


  #include <oneapi/tbb.h>
  #include <iostream>

  int main(){
    using namespace oneapi;
    auto concurrency = std::thread::hardware_concurrency();

    auto arena_bg = tbb::task_arena(tbb::task_arena::automatic);
    auto arena_fg = tbb::task_arena(tbb::task_arena::automatic);
    
    auto job = [&]() {
        arena_fg.execute([&]() {
            tbb::task::suspend([&](tbb::task::suspend_point suspend_point) {
                arena_bg.enqueue([&, suspend_point]() { 
                    std::cout << "If you can read this, all is fine\n";
                    tbb::task::resume(suspend_point);
                });
            });
        });
    };

    tbb::task_group jobs;
    for (unsigned i = 0; i < concurrency; i++)
        jobs.run(job);
    jobs.wait();
   
    return 0;
  };

The reproducer is not reliable. Sometimes it terminates fine, sometimes it deadlocks as tasks enqueued in bg_arena are never executed.
So I am unsure what is expected behavior should be: Are the worker threads resulting from suspended tasks still bound to the original arena or should they seek work in any arena?

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