操作系统 Loaderlock 的工作原理

发布于 2024-09-06 07:25:53 字数 233 浏览 4 评论 0原文

我试图更详细地了解操作系统加载锁如何与 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

蝶…霜飞 2024-09-13 07:25:53

当两个线程尝试以不同的顺序获取两个锁时,可能会发生死锁

  • 线程 A 获取锁 A,然后尝试获取锁 B
  • 同时,线程 B 获取锁 B,然后尝试获取锁 A

正在运行 DllMain 的线程已经获取了隐式 O/S 锁:因此他们(Microsoft)认为这可能是该线程尝试获取任何其他第二个锁是不安全的(例如,因为另一个线程可能已经拥有该锁并且当前被隐式操作系统锁阻塞)。

A deadlock can happen when two threads try to acquire two locks in different sequence.

  • Thread A gets lock A and then tries to get lock B
  • Meanwhile thread B gets lock B and then tries to get lock A

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).

鱼窥荷 2024-09-13 07:25:53

这是正确的。

任何此类执行都是非法的,因为
它可能会导致死锁并使用
初始化之前的 DLL
由操作系统的加载程序。

可以在此处找到更多信息:LoaderLock MDA(MSDN 网站)

that is correct.

Any such execution is illegal because
it can lead to deadlocks and to use of
DLLs before they have been initialized
by the operating system's loader.

More information can be found here: LoaderLock MDA (MSDN Website)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文