Thread safety of std::mutex

c++, multithreading, mutex, std, thread-safety

Solution

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.

Problem

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.

Original source