为什么我得到“检测到LoaderLock"?调试时发出警告? [英] Why am I getting the "LoaderLock was detected" warning when debugging?

查看:249
本文介绍了为什么我得到“检测到LoaderLock"?调试时发出警告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为AutoCAD 2009开发一个附加组件.项目输出是一个类库.当我尝试调试和加载类库时,我收到此"LoaderLock检测到消息".我已经在一段时间内编写了这些附加组件,这是我所见过的此类消息中的第一条.

I'm developing an add-on for AutoCAD 2009. The project output is a class library. When I attempt to debug and load the class library, I get this "LoaderLock was detected message." I've been writing these add-ons for awhile and this is the first message of this type I've seen.

  1. 我从哪里开始尝试解决这个问题?
  2. 什么是LoaderLock?为什么现在困扰我?

检测到LoaderLock 消息:尝试在OS Loader锁内进行托管执行.不要尝试在DllMain或图像初始化函数中运行托管代码,因为这样做可能会导致应用程序挂起.

LoaderLock was detected Message: Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.

我去了Debug -> Exceptions -> "Managed Debugging Assistants",找到了"LoaderLock",然后取消选中"Thrown"复选框.

I went to Debug -> Exceptions -> "Managed Debugging Assistants", found "LoaderLock" and unchecked the "Thrown" checkbox.

我可以再次调试,但是我做了什么,为什么必须这样做?这会给我造成其他问题吗?

I can debug again but what did I do and why did I have to do it? Will this cause other problems for me?

推荐答案

加载程序锁是系统使用的进程范围锁,系统用于同步对将DLL加载到进程地址空间中的访问.加载DLL,免费DLL,查询DLL信息等功能均获得了加载程序锁.通常,对开发人员影响最大的是在DllMain运行时也保持了加载程序锁定-这意味着在运行代码时可以保留通常不知道的OS锁定.

The loader lock is a process-wide lock used by the system to synchronize access to loading DLL's into a process address space. Functions that load DLL's, free DLL's, query DLL info, etc., all acquire the loader lock. What typically impacts developers the most is that the loader lock is held while DllMain is running as well - this means that an OS lock that you aren't normally aware of can be held while running your code.

在锁定层次结构中,可以将加载程序锁定视为处于非常低的级别. DllMain期间在加载程序锁定下运行的代码可能是导致死锁的原因.例如,CLR有自己的一组内部锁,在加载DLL时可以持有.如果从DllMain内调用托管代码,则可能导致线程上的CLR在按住加载程序锁的同时获取这些锁之一.如果另一个线程上的CLR已获得该锁(导致DllMain中的原始线程阻塞),然后尝试加载将获取加载程序锁的DLL,则您的进程将死锁.

The loader lock can be viewed as being at a very low level in the lock-hierarchy. Code running under the loader lock during DllMain can be the cause of deadlocks. For instance, the CLR has its own set of internal locks which it could hold while loading DLL's. If you call managed code from within your DllMain, you could cause the CLR on your thread to acquire one of these locks while holding the loader lock. If the CLR on another thread had acquired that lock (causing the origin thread in DllMain to block) and then tried to load a DLL which would acquire the loader lock, your process would deadlock.

这听起来像CLR正在尝试抢先检测加载程序锁下正在运行的托管代码.当您在调试器中看到此故障的堆栈时,请确定是什么原因导致托管代码从DllMain中运行,然后将其删除.

It sounds like the CLR is trying to preemptively detect running managed code under the loader lock. When you see the stack from this failure in the debugger, identify what is causing your managed code to be running from within a DllMain and remove it.

这篇关于为什么我得到“检测到LoaderLock"?调试时发出警告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆