Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
48 Views

Enqueued tasks never gets picked up.

I have the following pattern

parallel_for (blocked_range(0 , max),  [ ] (r) {

for (size_t i = r.begin(); i != r.end(); ++i) {

         ctx  = make_unique<tbb::task_group_context>();

         waitTask = (new (tbb::task::allocate_root(*ctx))

                         tbb::empty_task); 

        waitTask->set_ref_count(2);

        auto& workerTask = *new (waitTask->allocate_child()) WorkerTask(name);

        tbb::task::enqueue(workerTask);    

        waitTask->wait_for_all();  // wait for children to complete.

    }

}

I get a hang with all threads in receive_or_steal_task, but the "execute" of WorkerTask never being called.

Things work fine if I wait on all waitTasks   outside of the parallel_for in a different parallel_for.

OR

A sequential for loop in place of parallel_for in the above example also works fine .

 

0 Kudos
1 Reply
Highlighted
48 Views

tbb::task::spawn () instead

tbb::task::spawn () instead of tbb::task::enqueue() also works well. But  we need enqueue as we don't want to force require a wait() to guarantee the execution of the workerTask.

0 Kudos