According to TBB manual:
Make sure to call set_reference_count(3) before spawning any children. Failure to do so results in undefined behavior.
I've tried. Really fails.
In the loop within the task 'A' on some condition I need to spawn task 'B' in sake of performance. I do not know beforehand how many will be spawned, but I need to wait for them in the end of task 'A'.
Is that possible?
Of course I can postpone spawning the tasks, queue them into some local memory and spawn after the loop when the numbers are already counted. I suspect that this will significantly slow down my algorithm, so I have to check somehow.