Community
cancel
Showing results for 
Search instead for 
Did you mean: 
missing__zlw
Beginner
45 Views

Does spin_mutex work here?

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
45 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