gpt4 book ai didi

c++ - 我应该在 dlopen 之前锁定吗?

转载 作者:太空宇宙 更新时间:2023-11-04 10:23:56 27 4
gpt4 key购买 nike

我有一个 *.so 库,它使用 dlopen 从系统库中获取一些信息。库可以同时被多个应用程序使用。也许这是一个愚蠢的问题,但我应该在对它进行 dlopen 之前聚集库吗?我没有在任何地方找到直接答案。

最佳答案

与评论中所说的类似,除非您正在访问可能会改变您的共享资源,否则您不需要信号量(群)。 (IE。访问共享内存并需要确保该数据的并发性)。动态加载 ... dlopen()... 的工作方式

Those two routines are actually simple wrappers that call back intothe dynamic linker. When the dynamic linker loads a library viadlopen(), it does the same relocation and symbol resolution it does onany other library, so the dynamically loaded program can without anyspecial arrangements call back to routines already loaded

由于链接的工作方式,对 GOT/PLT 的重定位和修改是在(调用 dlopen 的进程)的内存空间中完成的,而不是共享对象映射的内存空间。

If a hundred processes use a shared library, it makes no sense to have100 copies of the code in memory taking up space. If the code iscompletely read-only, and hence never, ever, modified

将共享对象保存在只读内存中,您永远不必担心它们会突然在您身上发生变化,所以也不需要成群结队 :)!

注意:因为您有一个链接到其他共享对象的共享对象......初始共享对象的 GOT 需要更新/修改使用 dlopen() 加载的库的重定位......但这是存储在进程唯一内存空间的 r/w 段中,而不是共享对象的内存空间中。

the shared library must still have a unqiue data instance in eachprocess...the read-write data section is always put at a known offsetfrom the code section of the library. This way, via the magic ofvirtual-memory, every process sees its own data section but can sharethe unmodified code

关于c++ - 我应该在 dlopen 之前锁定吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42525843/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com