Search code examples
c++boostboost-thread

C++ Boost::thread upgradable mutex "try upgrade lock"?


I implemented boost upgradable mutexes following the top answer here Example of how to use boost upgradeable mutexes

What I would like to do is to "try" whether or not the upgrade will block: if the upgrade will not block performs the upgrade, otherwise don't lock it and returns.

Is there any function to do so?


Solution

  • Yes there is :
    -bool try_lock_upgrade_for(duration d)
    -bool try_lock_upgrade_until(time when)

    see http://www.boost.org/doc/libs/1_52_0/doc/html/thread/synchronization.html#thread.synchronization.mutex_types.upgrade_mutex