Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Shant_H_
Beginner
24 Views

Making Parallel Sort Comparator Thread Safe

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!

0 Kudos
1 Reply
RafSchietekat
Black Belt
24 Views

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.