Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.

TBB set reference count


I am new to Intel TBB. I am not clear on the purpose of setting a task's reference count to 3 while waiting on the 2 children to get executed.
My doubt is if the individual child tasks complete their execution and reduce the reference count by 1 . and eventually on the completion of the 2 child tasks the ref count now is zero and hence the parent/root can be executed. But what is the purpose to set it to 3?

PL correct me if my concept is wrong.

0 Kudos
1 Reply
Black Belt
The extra reference is to protect the parent against being automatically spawned by a thread that just finished execution of the parent's last remaining child. The reference count thus integrates a conceptual pure reference count (only the child tasks) with a conceptual status field (automatically spawn after last child or not?) into one real atomic integer that makes sense if you think of the wait_for_all() or similar call as needing its own reference, which is also validated by a simpler implementation that merely selects an appropriate threshold (wait_for_all() returns when the reference count drops down to one, instead of zero).