• Advertisement
Sign in to follow this  

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

This topic is 2735 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
Advertisement
Sign in to follow this  

  • Advertisement