操作系统 Loaderlock 的工作原理
我试图更详细地了解操作系统加载锁如何与 Windows 中 DLL 的加载和卸载相关。
据我了解,当创建/销毁新线程和/或加载/卸载新 DLL 时,每个加载的 DLL 都会收到通知。
那么这是否意味着 DllMain 函数在锁内运行,并且在它运行时没有其他线程可以访问它,并且如果您要在该函数中创建另一个线程,您可以挂起该进程甚至操作系统?
我的理解正确吗?
有一些文章可以解释这一点吗?
I'm trying to understand in a bit more detail how a OS loaderlock is used in relation to the loading and unloading of DLL's in Windows.
I understand that every loaded DLL get notified when a new thread is created/destroyed and or a new DLL is loaded/unloaded.
So does that mean that the DllMain function is run inside a lock and no other thread can access it while it is running, and if you were to create another thread in that function, you could hang the process or even the OS?
Is my understanding correct?
Is there some article somewhere that explain this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
当两个线程尝试以不同的顺序获取两个锁时,可能会发生死锁。
正在运行 DllMain 的线程已经获取了隐式 O/S 锁:因此他们(Microsoft)认为这可能是该线程尝试获取任何其他第二个锁是不安全的(例如,因为另一个线程可能已经拥有该锁并且当前被隐式操作系统锁阻塞)。
A deadlock can happen when two threads try to acquire two locks in different sequence.
A thread that's running DllMain has already acquired an implicit O/S lock: therefore they (Microsoft) reckon that it may be unsafe for that thread to try to acquire any other, second lock (e.g. because a different thread might already own that lock and be currently blocked on the implicit O/S lock).
这是正确的。
可以在此处找到更多信息:LoaderLock MDA(MSDN 网站)
that is correct.
More information can be found here: LoaderLock MDA (MSDN Website)