谁使用 c# 中的 lock 关键字锁定了我的东西
我的代码中有 lock 关键字。它冻结是因为其他东西锁住了这些东西。是否有某种命令或实用程序可以用来查看谁或什么?
I have the lock keyword in my code. It freezes because something else has the stuff locked. Is there some sort of command or utility I can use to see who or what?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用 Windbg 附加到进程,并使用 sosex.dll 通过 dlk 命令查看哪些线程发生死锁。
http://www.stevestechspot.com/SOSEXV40NowAvailable.aspx
You can attach to the process with windbg and use sosex.dll to see what threads are deadlocked with the dlk command.
http://www.stevestechspot.com/SOSEXV40NowAvailable.aspx
如果您使用锁,那么您应该在您控制的对象上使用它。通常,这是一个虚拟对象,仅用于您的锁,即
If you are using lock, then you should be using it on an object you control. Usually, this is a dummy object only used for your locks i.e.
不幸的是,没有简单的答案......但您可以使用诸如 CHESS 一路为您提供帮助。最终,您可能必须检查代码中是否存在可能导致死锁的竞争条件。在任何看到锁定语句或其他线程同步对象(例如监视器、互斥体等)的地方,您都需要检查它们锁定的内容,并找到锁定同一事物的其他代码片段
Unfortunately, there is no simple answer ... but you can use tools such as CHESS to help you along the way. Ultimately, you will probably have to examine your code for race conditions that could result in deadlocks. Any place that you see a lock statement or other thread sync object (such as Monitors, Mutex, etc.) you will want to examine to see what they are locking on and find the other pieces of code that lock on the same thing
我认为您可以使用 VS.NET 附加到挂起的进程并单击暂停。然后调用“线程”窗口(“调试”-->“Windows”-->“线程”)并检查哪些线程被锁定以及原因。这看起来是最简单的解决方案。
I think that you can use VS.NET to attach to the hung process and click the pause. Then invoke the Threads window (Debug-->Windows-->Threads) and check which threads are locked and why. This looks to be the easiest solution.