A basic question on task reference count

A basic question on task reference count

I still have trouble understanding the role of task reference count: suppose a parent task created 3 children task and wait for them to finish, then according to the examples, I should set the reference count of the parent task to 3+1=4. But what if I want to have the parent task discarded as soon as it spawns the children tasks, how should I set its reference counter? I'm thinking 0. Wrong answer?

2 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Then they should be root tasks instead of child tasks, so they won't try to decrement a reference count that no longer exists, and quite likely you might want to enqueue them instead, but that's difficult to say without knowing why you would want the creating task to be discarded (have you considered a continuation instead?).

Leave a Comment

Please sign in to add a comment. Not a member? Join today