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

Thread Local Storage Question

What happens to TLS combinable and enumerable_thread_specific objects between calls to parallel algorithms such as parallel_for? Are they destroyed? If the task_group object which initialized TLS objects is destroyed, does it destroy the TLS objects as well? What if the task_scheduler_init is destroyed or initialize method is called? What happens to TLS objects?

Thank you,
0 Kudos
1 Reply
New Contributor III
These objects follows the same life-time rules as C++ objects of any other type with the following exception. You can think of them as a list (or vector), elements of which correspond to individual threads that accessed it. Thus when a thread gets destroyed, the element that corresponded to it is erased too. Therefore manipulations with task_scheduler_init may affect the contents of TBB TLS objects, but not their lifetime. Note also that I said "may affect". This is because terminating a particular task_scheduler_init instancenot not always destroys underlying threads.
0 Kudos