Hello,
I'm using parallel_sort and regretfully my comparator needs to use a object that is not thread safe. I can make copies of this object for each thread and then the comparator would just need to use the right copy for the thread it is on, kind of like a thread_local but not global.
I'm looking for some tips on how to achieve this with TBB. I know task_scheduler_observer and enumerable_thread_specific are both options for implementing thread_locals but I'm not sure which is better in my case.
Thanks in advance!
Link Copied
task_scheduler_observer is not about thread-local storage.
Just use "tbb::enumerable_thread_specific<Comparator> ets_c(c);", with c your prototype Comparator.
(Added) Oh yes, you still have to pass it to the sort algorithm, without having it copied... probably with a simple wrapper object, with a member variable that's a pointer or reference to ets_c.
For more complete information about compiler optimizations, see our Optimization Notice.