#2156·oneTBB

Potential deadlock: FIFO task enqueued during local_wait_for_all may not be consumed in single-slot configuration

Author: darknesswindCreated Aug 10, 2026Updated Aug 23, 2026
Labelsbug

Summary

When local_wait_for_all sets m_properties.fifo_tasks_allowed = false (in src/tbb/task_dispatcher.h at commit fe9bfc5870679f87cfafe4f16d5735e718c1a4bc, line ~302), I believe a scenario can arise where a FIFO task enqueued after a thread goes into wait may not be consumed when there is only a single arena slot/worker, potentially resulting in a deadlock.

cpp
    oneapi::tbb::task_group tg;
    oneapi::tbb::task_arena ta(1, 0);

    ta.enqueue([&ta]()
    {
        oneapi::tbb::task_group inner;
        ta.enqueue([]() { /* do something */ }, inner);
        inner.wait();
    }, tg);
    ta.wait_for(tg);

Version

v2022.3.0

Environment

Reproduction is expected to be independent of OS/compiler because this is a scheduler logic concern visible in the source. If you need specific environment info I can provide details from my system.

Observed Behavior

  • In task_dispatcher::local_wait_for_all (src/tbb/task_dispatcher.h), the code saves the current properties into dl_guard.old_properties and immediately after sets:

    m_properties.outermost = false; m_properties.fifo_tasks_allowed = false;

  • receive_or_steal_task (called later in the dispatch loop) receives fifo_allowed from dl_guard.old_properties.fifo_tasks_allowed, so the current dispatch iteration checks FIFO eligibility based on the old properties.

  • My concern is a timing / single-slot scenario: if the runtime has only one arena slot (one worker) and that thread enters local_wait_for_all, then a task is enqueued into the FIFO stream while the thread is waiting. Depending on the ordering of idle/published flags and the m_properties change, that enqueued FIFO task might not become visible/consumable by the waiting thread (or by stealing logic), which could leave the system stuck waiting for work that is never executed.

  • In short: with a single slot and FIFO tasks disallowed by properties at the relevant time, an enqueue that happens during the wait may not be consumed, potentially causing a deadlock.

Expected Behavior

A FIFO task enqueued while a thread is in local_wait_for_all should be discovered and executed (or published for stealing) in a way that prevents the system from deadlocking, even in the single-slot case. Changing m_properties for the current dispatcher should not prevent FIFO tasks from being consumed if the outer/previous context allowed them or if the tasks were enqueued while the thread was idle.

Steps To Reproduce

cpp
    oneapi::tbb::task_group tg;
    oneapi::tbb::task_arena ta(1, 0);

    std::mutex mtx;
    std::condition_variable cv;

    ta.enqueue([&ta, &mtx, &cv]()
    {
        oneapi::tbb::task_group inner;
        inner.run([] {
            printf("test1");
        });
        ta.enqueue([]() {
            printf("test2");
        }, inner);
        inner.wait();

        std::unique_lock<std::mutex> lock(mtx);
        cv.notify_all();
    }, tg);

    // do something else
    {
        std::unique_lock<std::mutex> lock(mtx);
        cv.wait(lock);
    }

    ta.wait_for(tg);