문제

I have found in the docs that a unique_lock can try "to acquire the lock in a non-blocking fashion".

Is it the unique_lock's thread that isn't blocked as it tries to acquire the lock in the "non-blocking fashion"? If so, does it simply fail gracefully? Will unlock?

Also, since notify_one doesn't throw, does that mean that if it cannot notify, it will also fail gracefully?

If the unique_lock can be set not to wait for a successful lock but fail gracefully and move on with graceful failures for unlock and notify_one, how can a unique_lock be set this way?

도움이 되었습니까?

해결책

Something like boost::unique_lock lock(my_lockable, boost::try_to_lock); should do the trick.

lock.owns_lock() will return true if the lock were acquired. If it wasn't acquired you should not attempt to release it.

It should always be safe to call notify_one even if no condition is waiting for it.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top