質問

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