Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.
Announcements
This community is designed for sharing of public information. Please do not share Intel or third-party confidential information here.
2421 Discussions

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

Nishikawa__Mitsuru
495 Views

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
Mariya_P_Intel
Moderator
380 Views

Dear @Nishikawa__Mitsuru,

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

Thanks, Mariya


Reply