Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Nested task_group deadlock

nagy
New Contributor I
240 Views
I'm having some issues with deadlocks while running a tbb::task_group inside a tbb::parallel_for_each.
e.g.
[cpp]class worker_with_deadlock
{
    result result_;
    tbb::task_group tasks_;
public:
    ~worker_with_deadlock()
    {
        tasks_.cancel();
        tasks_.wait();
    }

    result run()
    {
         tasks_.wait();

         auto my_result = std::move(result_);

         tasks_.run([=]
         { 
              result_ = do_work();
         });

         return my_result;
    }
}

class worker_without_deadlock
{
    result result_;
public:
    result run()
    {
         auto my_result = std::move(result_);

         result_ = do_work();

         return my_result;
    }
}

void run_workers()
{
     // This will deadlock?
     tbb::parallel_for_each(workers.begin(), workers.end(), [&](worker_with_deadlock& worker)
     {
          result[worker.tag()] = worker.run();
     });

     // This will not deadlock?
     tbb::parallel_for_each(workers.begin(), workers.end(), [&](worker_without_deadlock& worker)
     {
          result[worker.tag()] = worker.run();
     });
}[/cpp]
Unfortunately I do not have a code which you can use to reproduce the problem with at this moment.
Do you have any ideas as to what might cause this?
0 Kudos
1 Reply
RafSchietekat
Valued Contributor III
240 Views
I'm afraid this code isn't very helpful to get an understanding of what you are trying to do...
0 Kudos
Reply