Std :: mutex thread safety

Is it possible to lock std :: mutex on one thread and unlock it on another thread? This is a theoretical question without any specific engineering context. I'm just curious.

+3


source to share


2 answers


C ++ Standard, [thread.mutex.requirements.mutex] / 21 and 22:

The expression m.unlock()

must be well formed and have the following semantics:

    Required: The calling thread must have a mutex.



Violation of requirements in the Requires clause causes undefined behavior.

+7


source


cppreference reads:



The mutex must be locked by the current thread of execution, otherwise the behavior is undefined.

+6


source







All Articles