- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Link Copied
1 Reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page