开发者

how to have a shared variable in library across many applications in linux?

开发者 https://www.devze.com 2022-12-14 17:15 出处:网络
how to have a shared variable in library across all application in linu开发者_运维百科x (c++)?You can use POSIX shared memory to create a shared memory segment, and place the variable there.You will n

how to have a shared variable in library across all application in linu开发者_运维百科x (c++)?


You can use POSIX shared memory to create a shared memory segment, and place the variable there. You will need to synchronise access to the shared variable using POSIX semaphores.

See the shm_overview(7) and sem_overview(7) man pages to get started.


Likewise, you can use posix shared memory or just mmap() a file and have the variable exist in that area of memory.

The loader will not automatically do this with a special section such as the "shared" one in Win32 DLLs. This is probably not a big deal as it's a bit of an anti-feature anyway.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号