Initializing the Library Is Your Job

Each thread must initialize the Threading Building Blocks library using tbb::task_ scheduler_init before using an algorithm template or the task scheduler. If you use the default task scheduler for the whole program and just define tasks using algorithm templates as shown in the earlier chapters of this book, it is enough to define tbb::task_scheduler_init once, in your main program. However, if you create your own tasks as shown in this chapter, each task has to initialize the scheduler as well.

Refer to the section “Initializing and Terminating the Library” in Chapter 3 for more information on the proper initialization and optional parameters to tbb::task_ scheduler_init.

The section “Mixing with Other Threading Packages” in Chapter 10 explains how to construct task_scheduler_init objects if your program creates threads itself using another interface.

Get Intel Threading Building Blocks now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.