c++多線程鎖能夠使用absl::Mutex std::mutex這兩種,下面是demo代碼。c++
使用absl:Mutex的時候打印:git
[mutex.cc : 1338] RAW: Cycle:
[mutex.cc : 1352] RAW: mutex@0x683b68 stack:
@ 0x438562 absl::DebugOnlyDeadlockCheck()
@ 0x4387b2 absl::Mutex::Lock()
@ 0x4353d0 runThread2()
@ 0x7f12851c5184 start_thread多線程
[mutex.cc : 1352] RAW: mutex@0x683b70 stack:
@ 0x438562 absl::DebugOnlyDeadlockCheck()
@ 0x4387b2 absl::Mutex::Lock()
@ 0x4352e2 runThread1()
@ 0x7f12851c5184 start_thread線程
[mutex.cc : 1357] RAW: dying due to potential deadlock3d
能夠看到谷歌的鎖代碼有自動檢查死鎖功能,很是強悍。get
std::mutex的鎖直接死鎖無任何提示。qt