Reputation: 3882
Can I lock std::mutex
in one thread and unlock it in other thread? This is theoretical question without any specific engineering context. I am just curious.
Upvotes: 3
Views: 598
Reputation: 60979
C++ standard, [thread.mutex.requirements.mutex]/21 and 22:
The expression
m.unlock()
shall be well-formed and have the following semantics:Requires: The calling thread shall own the mutex.
A violation of requirements in a Requires clause induces undefined behavior.
Upvotes: 7
Reputation:
The mutex must be locked by the current thread of execution, otherwise, the behavior is undefined.
Upvotes: 6