是共享库/dll中的全局变量,跨进程共享 [英] Is global variable in a shared library / dll, shared across process

查看:41
本文介绍了是共享库/dll中的全局变量,跨进程共享的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个共享库(.so)和 dll.我有一个在多个线程中更新的全局变量.所以我有用于同步的互斥锁.

I am developing a shared library(.so) and dll. I have a global variable which is updated in multiple threads. So I have mutex lock for synchronization.

我不清楚共享库中的全局数据是否跨进程共享.如果是,那么我需要使用信号量进行同步.据我所知,全局变量是数据段的一部分,所以我想了解 dll 如何跨进程管理全局数据.任何信息 w.r.t.dll 格式和段会很有帮助.

I am not clear whether global data in shared library is shared across process. If it is then I need to use semaphores for synchronization. As I understand global variables are part of data segment so I wanted to understand how dll manages the global data across processes. Any information w.r.t. dll format and segment will be helpful.

谢谢.

推荐答案

默认情况下,不,全局变量不跨进程共享.

By default, no, global variables are not shared across processes.

但是,您可以使用数据段 (data_seg) 来跨进程共享全局变量.您可以在标题为如何与应用程序或其他 DLL 共享 DLL 中的数据?"

However, you can use a data segment (data_seg) in order to share global variables across processes. You can find more information on MSDN in the article titled "How do I share data in my DLL with an application or with other DLLs?"

这篇关于是共享库/dll中的全局变量,跨进程共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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