I'm working on a message reading and handling application trying to solve threading by TBB only.
Imagine a root task being started in a main loop like this:
usleep(100 * 1000);
PacketReadingTask& task = *new(tbb::task::allocate_root()) PacketReadingTask();
The root task will read the next available UDP packet from the receiving buffer, create a
continuation task and allocate a child task for the handling of the message. If a message
was handled, the task will also recycle itself as a child of the continuation task.
This means that as long as there are packets, it will continue recursively creating tasks
All that works pretty well, but here is the problem:
If there is a particular packet handling taking very long (let's say 2 seconds) and there
are no more packets available at a certain moment after that, it won't be able to
check for new packets until all children of the root task are finished.
I was wondering if there is a way to spawn root tasks and continue with the code
directly after that?
Or maybe I have to think in a different way to solve my problem?
Any tip would be appreciated.
Thanks in advance,