#include <iostream>
#include <mutex>
using namespace std;
int main()
{
mutex m;
m.lock();
cout << "locked once\n";
m.lock();
cout << "locked twice\n";
return 0;
}
输出:
./a.out
locked once
locked twice
程序是否需要在第二次锁定时死锁,即互斥体被同一个线程锁定两次?
最佳答案
If lock is called by a thread that already owns the mutex, the behavior is undefined: the program may deadlock, or, if the implementation can detect the deadlock, a resource_deadlock_would_occur error condition may be thrown.
关于linux - 为什么这个 C++11 程序不会死锁?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33059303/