我可以在一个线程中锁定 std::mutex
并在另一个线程中解锁吗?这是没有任何特定工程背景的理论问题。我只是好奇。
最佳答案
C++ 标准,[thread.mutex.requirements.mutex]/21 和 22:
The expression
m.unlock()
shall be well-formed and have the following semantics:Requires: The calling thread shall own the mutex.
违反 Requires 子句中的要求会导致未定义的行为。
关于c++ - std::mutex 的线程安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27257440/