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

Thread local storage data structure constructed preliminarily is assigned per each thread


Dear TBB experts,


Relating to my previous post, "Thread ID as index from zero to thread number",

I would like to prepare some data pool, cache data, per each thread (or task?) in RAII (construction) step before massive iterative computations,

so as not to bring about data race between each running thread (or task?). Currently, I prepare it as std::vector which contains thread number elements.


As an alternative way, I suppose that thread local storage (tbb::combinable, or tbb::enumerable_thread_specific) will work well,

but I do not know they are assigned and referred in one-to-one correspondence, which is prepared before the parallel loop.

### I explain what I meant by psuedocode,

    tbb::enumerable_thread_specific tls_data;

    // data pool is prepared in RAII step

    tbb::paralle_for_each(preparator.begin(), preparator.end(),

      [](::iterator iter){

          // HERE, tls_data is prepared per each thread (or task? )


    // some massive computation step

    tbb::paralle_for_each(preparator.begin(), preparator.end(),

      [](::iterator iter){

          // HERE, tls_data would be used without data race, is it guranteed?




I would appreciate it if you could tell me my question.


Kind regards





0 Kudos
1 Reply

Dear @Nishikawa__Mitsuru,

Apologies for a lack of response. Please let us know if the question is still actual or not.

Thanks, Mariya

0 Kudos