Created
March 6, 2014 07:50
-
-
Save stevenRush/9384415 to your computer and use it in GitHub Desktop.
Shared mutex upgrade example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
boost::shared_mutex _access; | |
void reader() | |
{ | |
boost::shared_lock< boost::shared_mutex > lock(_access); | |
// do work here, without anyone having exclusive access | |
} | |
void conditional_writer() | |
{ | |
boost::upgrade_lock< boost::shared_mutex > lock(_access); | |
// do work here, without anyone having exclusive access | |
if (something) { | |
boost::upgrade_to_unique_lock< boost::shared_mutex > uniqueLock(lock); | |
// do work here, but now you have exclusive access | |
} | |
// do more work here, without anyone having exclusive access | |
} | |
void unconditional_writer() | |
{ | |
boost::unique_lock< boost::shared_mutex > lock(_access); | |
// do work here, with exclusive access | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment