gpt4 book ai didi

c++ - boost::interprocess 映射线程安全

转载 作者:塔克拉玛干 更新时间:2023-11-03 06:42:50 32 4
gpt4 key购买 nike

现在查看此链接:

http://www.boost.org/doc/libs/1_56_0/doc/html/interprocess/quick_guide.html#interprocess.quick_guide.qg_interprocess_map

我打算用它来映射 UNIX 系统上进程之间的内存。我是否必须为多个进程写入/读取实现自己的保护,或者它是否已经内置?文档在这方面似乎不清楚。

最佳答案

您需要同步对共享内存中容器的所有访问。

例如here :

As mentioned before, the ability to shared memory between processes through memory mapped files or shared memory objects is not very useful if the access to that memory can't be effectively synchronized. This is the same problem that happens with thread-synchronization mechanisms, where heap memory and global variables are shared between threads, but the access to these resources needs to be synchronized typically through mutex and condition variables.

还有 here

Using shared memory, we can avoid two data copies, but we have to synchronize the access to the shared memory segment.

Shared memory avoids this overhead, but we need to synchronize both processes

关于c++ - boost::interprocess 映射线程安全,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26020855/

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