
Suppose I have a boost::upgrade_lockboost::shared_mutex. When I want to create the boost::upgrade_to_unique_lockboost::shared_mutex and upgrade to exclusive locking, this blocks until all the shared lock holders leave. However, it does not appear that there is a non-blocking version of this, unlike, say, making a boost::unique_lockboost::shared_mutex and passing in boost::try_to_lock. So what should I do in order to create my own "try-upgrade" lock? I'm trying to use it like so: boost::upgrade_lockboost::shared_mutex upgradeLock(mutex); ... if (...) { // Substitute for boost::upgrade_to_unique_lockboost::shared_mutex, but also with aspects of // boost::try_to_lock, basically my_upgrade_to_unique_lockboost::shared_mutex deferredWriteLock(lock); // Do stuff where it doesn't matter whether I have exclusive or not, while the readers leave if (!deferredWriteLock) deferredWriteLock.lock(); // Now we need exclusive // We have exclusive, do more stuff } // Back to regular upgrade_lock here