Why is std :: unique_lock not derived from std :: lock_guard

std::lock_guard

and the std::unique_lock

interfaces look very similar in their general part (constructors and destructor).

Why is there no hierarchical relationship between them?

+3


source to share


1 answer


They have no wildcard semantics: they are
lock_guard

guaranteed to be blocked after their entire lifetime.
unique_lock

does not guarantee that it will not follow "IS A" -rle ( unique_lock

it cannot lock_guard

, since it offers fewer guarantees).

Also a unique_lock

based implementation lock_guard

would not be trivial (maybe even impossible) for this reason.



Obviously, the same is true and vice versa: while you can implement lock_guard

in terms of unique_lock

(private inheritance), it lock_guard

does not provide the same functionality as ( lock()/unlock()

) unique_lock

, so it cannot be publicly derived from it.

+8


source







All Articles