Sign in to follow this  

Should I use boost::upgrade_lock or just boost::unique_lock?

This topic is 2662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, is it much better to use boost::upgrade_lock and only change to boost::upgrade_to_unique_lock at a later stage, or should I just start off by using a boost::unique_lock??

for e.g


void FunctionA()
{
boost::shared_lock<boost::shared_mutex> read_lock(read_write_mutex_);

HashMap::iterator iter hash_map_.find("value");

if (hash_map_.end() == iter)
{
return;
}
else
{
boost::upgrade_to_unique_lock<boost::shared_mutex> write_lock(read_lock);

iter->second.value = 1000;
}
}



is that better or should I just use a unique lock at the start and do a exclusive lock all the way till the function ends?

regards

Share this post


Link to post
Share on other sites

This topic is 2662 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this