QMutex::lock:在线程 0xfe8(主线程?)中检测到死锁
我正在 GDB 中运行我的程序。我的程序需要为其工作创建 16 个线程。所有这些都很好。最后我收到错误 QMutex::lock: Deadlock detector in thread 0xfe8
这是 GDB
(gdb) run
Starting program: C:\dgrfb.run\client/DGRFB.exe
[New thread 4076.0xfe8]
[New thread 4076.0x368]
warning: >> Socket State Changed: QAbstractSocket::HostLookupState
warning: >> Socket State Changed: QAbstractSocket::ConnectingState
[New thread 4076.0x4b8]
warning: >> Socket State Changed: QAbstractSocket::ConnectedState
[New thread 4076.0x49c]
warning: Rect Area 0 2 DG::UpdateThread(0xa0d5220)
warning: Rect Area 0 3 DG::UpdateThread(0xa0d5548)
warning: Rect Area 1 0 DG::UpdateThread(0xa0d5870)
warning: Rect Area 1 1 DG::UpdateThread(0xa0d5b98)
warning: Rect Area 1 2 DG::UpdateThread(0xa0d5ec0)
warning: Rect Area 1 3 DG::UpdateThread(0xa0d61e8)
warning: Rect Area 2 0 DG::UpdateThread(0xa0d6510)
warning: Rect Area 2 1 DG::UpdateThread(0xa0d6838)
warning: Rect Area 2 2 DG::UpdateThread(0xa0d6b60)
warning: Rect Area 2 3 DG::UpdateThread(0xa0d6e88)
[New thread 4076.0x540]
warning: Rect Area 3 0 DG::UpdateThread(0xa0d71b0)
warning: Rect Area 3 1 DG::UpdateThread(0xa0d7568)
warning: Rect Area 3 2 DG::UpdateThread(0xa0d7cc0)
warning: Rect Area 3 3 DG::UpdateThread(0xa0d7fe8)
[New thread 4076.0x670]
[New thread 4076.0x6dc]
[New thread 4076.0x674]
[New thread 4076.0x3ac]
[New thread 4076.0x684]
[New thread 4076.0x434]
[New thread 4076.0x44c]
[New thread 4076.0x7e8]
[New thread 4076.0x408]
[New thread 4076.0x7e0]
[New thread 4076.0x42c]
[New thread 4076.0x814]
[New thread 4076.0x6f8]
[New thread 4076.0x8a4]
warning: QThread(0x3d58d8) tick
warning: Rect # 0 0 100 56
warning: Unmatched true
warning: Updating 0 0
warning: QMutex::lock: Deadlock detected in thread 0xfe8
现在的输出 哪个线程 0xfe8
是?它是主线程吗? 首先,我以为我已经调用了同一个 mutex.lock()
两次。或者 func_a()
和 func_b()
使用相同的互斥体。这就是造成僵局的原因。但没有发现任何这样的情况。那么从哪里开始调查呢?
I am running my Program in GDB. My Program needs to create 16 threads for its work. and all these works fine. at the end I get the Error QMutex::lock: Deadlock detected in thread 0xfe8
here is the GDB Output
(gdb) run
Starting program: C:\dgrfb.run\client/DGRFB.exe
[New thread 4076.0xfe8]
[New thread 4076.0x368]
warning: >> Socket State Changed: QAbstractSocket::HostLookupState
warning: >> Socket State Changed: QAbstractSocket::ConnectingState
[New thread 4076.0x4b8]
warning: >> Socket State Changed: QAbstractSocket::ConnectedState
[New thread 4076.0x49c]
warning: Rect Area 0 2 DG::UpdateThread(0xa0d5220)
warning: Rect Area 0 3 DG::UpdateThread(0xa0d5548)
warning: Rect Area 1 0 DG::UpdateThread(0xa0d5870)
warning: Rect Area 1 1 DG::UpdateThread(0xa0d5b98)
warning: Rect Area 1 2 DG::UpdateThread(0xa0d5ec0)
warning: Rect Area 1 3 DG::UpdateThread(0xa0d61e8)
warning: Rect Area 2 0 DG::UpdateThread(0xa0d6510)
warning: Rect Area 2 1 DG::UpdateThread(0xa0d6838)
warning: Rect Area 2 2 DG::UpdateThread(0xa0d6b60)
warning: Rect Area 2 3 DG::UpdateThread(0xa0d6e88)
[New thread 4076.0x540]
warning: Rect Area 3 0 DG::UpdateThread(0xa0d71b0)
warning: Rect Area 3 1 DG::UpdateThread(0xa0d7568)
warning: Rect Area 3 2 DG::UpdateThread(0xa0d7cc0)
warning: Rect Area 3 3 DG::UpdateThread(0xa0d7fe8)
[New thread 4076.0x670]
[New thread 4076.0x6dc]
[New thread 4076.0x674]
[New thread 4076.0x3ac]
[New thread 4076.0x684]
[New thread 4076.0x434]
[New thread 4076.0x44c]
[New thread 4076.0x7e8]
[New thread 4076.0x408]
[New thread 4076.0x7e0]
[New thread 4076.0x42c]
[New thread 4076.0x814]
[New thread 4076.0x6f8]
[New thread 4076.0x8a4]
warning: QThread(0x3d58d8) tick
warning: Rect # 0 0 100 56
warning: Unmatched true
warning: Updating 0 0
warning: QMutex::lock: Deadlock detected in thread 0xfe8
Now Which thread 0xfe8
is ? Is it the Main Thread ?
First I thought I've called the same mutex.lock()
twice. or func_a()
and func_b()
are using the same mutex. thats causing the deadlock. But Not found any of such scenario.So Wheare to startthe investigation ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
很难回答哪个线程导致了死锁。然而,根据经验,尝试使用 QMutexLocker 来尽可能避免死锁尽可能。这样你的互斥体就会自动解锁。
It is very difficult to answer which thread is causing the dead-lock. However as a rule of thumb try to use QMutexLocker to avoid dead-locks as much as possible. This way your mutext will be unlocked automatically.
当我尝试从同一个线程两次锁定互斥锁时,我看到了此消息。使 QMutex 递归修复它。
I've seen this message when I tried to lock a mutex twice from the same thead. Making the
QMutex
recursive fixed it.