std::shared_lock release() method - how to use?

68 Views Asked by At

Documentation on the method (https://en.cppreference.com/w/cpp/thread/shared_lock/release) sounds confusing to me:

disassociates the associated mutex without unlocking (i.e., releasing ownership of) it 

I used to explore shared_lock and unique_lock based on the same mutex to implement read/write locking, but still can not grasp what's the point in disassociating the lock with the mutex it was built upon?

What could be a more or less real usecase?

1

There are 1 best solutions below

1
On BEST ANSWER

It seems analogous to std::unique_ptr::release() and you might use it in the same kind of places. For example if you have a lower-level API which requires a locked mutex to be passed in directly and it will unlock it later. Not a common use case, to be sure, but neither is std::unique_ptr::release().