除了这种交叉加锁,
void Foo()
{
std::lock_guard guard1{m_mutex1};
std::lock_guard guard2{m_mutex2};
...
}
void Bar()
{
std::lock_guard guard2{m_mutex2};
std::lock_guard guard1{m_mutex1};
...
}
看到好多这种死锁:
int ThreadProc() {
...
std::lock_guard guard{m_mutex};
...
}
void StopThread()
{
std::lock_guard guard{m_mutex};
if (m_thread != nullptr)
{
m_thread->join();
delete m_thread;
m_thread = nullptr;
}
}
--
FROM 114.241.228.*