I checked continuation now from the tutorial.pdf. Here is the problem i see:
I want to spawn 100 tasks. the last task that is executed spawns another 100 tasks. From those new 100 tasks the last one again spawns the first 100 tasks. this is repeated "forever".
When i spawn a ContinuationTask, it wont get deleted until all ChildTasks from the ContinuationTasks are ready. So i guess i will run into a stack overflow some time, because each ContinuationTask create new tasks. So its a never-ending recursion. But in fact it doesn t need to be a recursion, because i dont wait on a return value. I did not figure out yet, how to program my scenario.
I thought about hanging all child tasks to the same continuation task. But then i get a race condition with "set_ref_count". And when i try a mutex in it, it doesn t work either.
Well, I don't know what you don't understand. Don't try reusing the task objects; create a new one when you need it. The corpses of former tasks are kept in a pool in TBB, so the overhead to get a new one is low. Make the overhead of task object constructor low as well. If you need some data to persist between program stages, don't make these data part of a task; instead, keep it separately and make tasks reference it.
ok, i understand thank you. That sounds good. But i still go into a stack overflow or not? I implemented something now and its fast. but my memory is going higher and higher. I think because some continuation tasks start new continuation tasks in an endless recursion without the chance that they ever get freed.