I am trying to use both timed_mutex with the scoped_lock. I have successfully used the scoped_lock before by following some examples but now I don't seem to find my way around neither I am able to properly understand the boost documentation.
The desired behavior is the following: try to acquire an scoped_lock for x time, if successful return true otherwise return false.
Currently I have:
boost::timed_mutex _mutex;
boost::timed_mutex::scoped_lock scoped_lock(_mutex, boost::get_system_time() + boost::posix_time::miliseconds(10));
However when I try to find (through boost documentation or examples) if this scoped_lock will return a boolean or not I find nothing or find really different ways to do it.
Therefore I ask which is the correct way to do it, how does it exactly works and maybe some indication as to how correctly "read" the documentation of boost.
UPDATE:
So
boost::timed_mutex _mutex;
boost::timed_mutex::scoped_lock scoped_lock(_mutex, boost::get_system_time() + boost::posix_time::miliseconds(10));
if(scoped_lock.owns_lock()) {
// exclusive code
}
Will create a mutex which when I try to lock with scoped_lock.owns_lock() will try to acquire the lock during 10 miliseconds (in this case) and return false if the time's up and the lock wasn't acquired?