Community
cancel
Showing results for 
Search instead for 
Did you mean: 
renorm
Beginner
43 Views

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,
renorm.
0 Kudos
1 Reply
Andrey_Marochko
New Contributor III
43 Views

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.
Reply