Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

question on task::spawn

andreyryabov
Beginner
479 Views
When I call task::spawn does It mean that some other thread can execute this just spawned task before I spawn any other sibling task? If not when tasks become eligible for execution?
0 Kudos
3 Replies
andreyryabov
Beginner
479 Views
I'm confused by an advice given on page 168 of Thread Building Blocks book. It says "Allocate all siblings before of them starat to run, unless you are using allocate_additional_child_of". How shold I understend it? And how to acheive it. tbb does not allow to control when tasks starts running.
0 Kudos
Alexey-Kukanov
Employee
479 Views
Quoting - andreyryabov
I'm confused by an advice given on page 168 of Thread Building Blocks book. It says "Allocate all siblings before of them starat to run, unless you are using allocate_additional_child_of". How shold I understend it? And how to acheive it. tbb does not allow to control when tasks starts running.

As soon as you spawn a task you have no control over when it starts running, so you might just assume it already runs, or even finished.

That advice in the book, however, is too strong. Actually you can mix task allocation and spawns, as long as you appropriately set the reference counter before spawning any sibling task. Read the TBB Reference document, chapter 8.8 "Catalog of Recommended Task Patterns" for more detailed information of how the TBBtasks are supposed to use.
0 Kudos
andreyryabov
Beginner
479 Views

As soon as you spawn a task you have no control over when it starts running, so you might just assume it already runs, or even finished.

That advice in the book, however, is too strong. Actually you can mix task allocation and spawns, as long as you appropriately set the reference counter before spawning any sibling task. Read the TBB Reference document, chapter 8.8 "Catalog of Recommended Task Patterns" for more detailed information of how the TBBtasks are supposed to use.

Great!
Thank you!
0 Kudos
Reply