!syncblk 识别等待线程
当我在 Windbg 的死锁应用程序上使用 !syncblk 命令时,我得到了 以下输出。它显示哪个线程持有锁。但事实并非如此 指示哪些线程正在等待锁。我怎样才能识别 正在等待的线程? 。
0:004> !syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner
2 0016d12c 3 1 0014b1c0 1ab8 0 01292e3c System.Object
-----------------------------
Total 2
CCW 0
RCW 0
ComClassFactory 0
Free 0
when I ssued !syncblk command on a deadlocked application from windbg, I got
the following output. It shows which thread holds the lock. But it does not
indicate which threads are waiting for the lock. How can I identify the
threads that are waiting? .
0:004> !syncblk
Index SyncBlock MonitorHeld Recursion Owning Thread Info SyncBlock Owner
2 0016d12c 3 1 0014b1c0 1ab8 0 01292e3c System.Object
-----------------------------
Total 2
CCW 0
RCW 0
ComClassFactory 0
Free 0
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用
~*e!clrstack
查看所有托管堆栈。如果线程正在等待获取锁,您应该在其堆栈中看到一些适当的帧(例如,Monitor.TryEnter
)。You could look at all of the managed stacks using
~*e!clrstack
. If a thread is waiting to acquire a lock, you should see some appropriate frames in it's stack (e.g,Monitor.TryEnter
).如果您要解决死锁问题,您的第一个操作应该是加载 SOSEX.dll 并尝试
!dlk
命令,因为它将根据Monitor
和ReaderWriteLock
识别死锁。它甚至可以精确定位源代码中的确切位置。在某些情况下,
!dlk
命令无法按预期识别死锁。在这种情况下,您需要根据您的问题使用!syncblock
。要查找哪个线程正在尝试获取特定的锁,您可以使用~*e!clrstack
正如 @Liran 指出的。但是,您也可以使用~*e!dso
(它将转储堆栈上不同线程的引用)并查找对锁对象的引用。If you're troubleshooting a deadlock problem, your first action should be to load SOSEX.dll and try the
!dlk
command, as it will identify deadlocks based onMonitor
andReaderWriteLock
. It will even pinpoint the exact spot in the source code.In some cases the
!dlk
command doesn't identify deadlocks as expected. In that case you need to use!syncblock
as per your question. To find what thread is trying to acquire a specific lock, you can use~*e!clrstack
as @Liran points out. However, you can also use~*e!dso
(which will dump references on the stack for the different threads) and look for references to the lock object.