Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
25 Views

Nested task_group deadlock

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
Highlighted
Black Belt
25 Views

I'm afraid this code isn't very helpful to get an understanding of what you are trying to do...
0 Kudos