We are using the tbb task scheduler to let it organize the work we give it. Currently we create a root task and wait for the root task to finish:
_rootTbbTask = new(tbb::task::allocate_root()) TbbRootMessageTask(std::bind(&RootTbbTaskMessage));
RootTbbTaskMessage() is a function which does some initialisation and then waits indefinitely at a condition variable
All further tasks are either spawned or enqueued by using
thus making sure that tbb::task::spawn_root_and_wait(*_rootTbbTask) only continues when all children have finished
In order to terminate the task scheduler we unblock RootTbbTaskMessage() and call terminate after spawn_root_and_wait(...)
Is it possible to avoid 'allocate_additional_child' and instead create all further tasks as root tasks via tbb::task::allocate_root()? Or is it essential that all tasks have finished before 'tbb::task::spawn_root_and_wait(*_rootTbbTask)' lets the thread continue and terminate is called?
We tried to create all tasks via tbb::task::allocate_root() which worked fine for Windows system. However on Linux we got sporadic crashes during
task_scheduler_init::terminate() which made us wonder if our approach is ok.