Why does timelock not throw timeout exception in C ++ 0x?

C ++ 0x allows you to lock a mutex until a given time is reached and return a boolean message if the mutex is locked or not.

template <class Clock, class Duration>
bool try_lock_until(const chrono::time_point<Clock, 
                    Duration>& abs_time);

      

In some contexts, I am considering an exception where the lock fails due to a timeout. In this case, the exception must be more assigned.

To make a difference, the lock_until function can be used to get a timeout exception when the time has reached before the lock.

template <class Clock, class Duration>
void lock_until(const chrono::time_point<Clock, 
                Duration>& abs_time);

      

Do you think lock_until should be more adequate in some contexts? if so, which ones? If not, why is try_lock_until always the best choice?

+2


a source to share


1 answer


Can't you just check the return value and throw your own exception?

if ( ! my_lock.try_lock_until( my_start_time ) ) {
    throw realtime_error( "Couldn't start in time!" );
}

      



In addition, a quick look at the threading and exception libraries in FCD does not display the timing-related exception classes, so you don't need to type std::

for lock_until

.

+2


a source







All Articles