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

Does spin_mutex work here?

missing__zlw
Beginner
130 Views
I have a std map that I need to update in a parallized code section.
It looks like this :
if(bmultithread){
tbb::spin_mutex::scoped_lock plock(my_mutex);
cout<<"some test output here!!" << endl;
paPair = psUniSet->insert( pVData);
} else {
paPair = psUniSet->insert( pVData);
}
When I run my program in multi-thread mode, it crashes at the set insertion with seg fault. If I run in single thread mode, it works.
the psUniSet is a std:set.
So I wonder whether the spin_mutex is working here. Even with the spin_mutex, the test output is still scrambled, but that may due to the output buffereing.
What could be the problem here?
Thanks.
0 Kudos
1 Reply
Alexey_K_Intel3
Employee
130 Views

Where does the mutex that you use reside?The general rule is that the lock should have the same scope as the data to synchronize access to, otherwise you risk touse different mutex instances, thus making possible concurrent access to the data.

Reply