【发布时间】:2015-02-09 15:25:49
【问题描述】:
我正在尝试使用 Boost 中的进程间共享跨进程的结构。
我已将映射文件定义为使用空互斥锁,因为我在锁定它时遇到问题,我不介意自己进行同步。
我遇到的问题是寻找对象。
我有以下声明:
typedef boost::interprocess::basic_managed_mapped_file
< char,
boost::interprocess::rbtree_best_fit<boost::interprocess::null_mutex_family,boost::interprocess::offset_ptr<void>>,
boost::interprocess::flat_map_index>
my_mapped_file;
在流程 A 中,我这样做:
m_managedMappedFile.reset(new my_mapped_file(bip::open_or_create, filename, filesize));
auto hdr = m_managedMappedFile->find_or_construct<Foo>(bip::unique_instance)();
auto x = m_managedMappedFile->find<Foo>(bip::unique_instance);
正如我所料,它找到了对象。现在,在进程 B 中:
m_managedMappedFile.reset(new my_mapped_file(bip::open_only, filename));
auto ret = m_managedMappedFile->find<Foo>(bip::unique_instance);
由于某种原因,find 方法在进程 B 中返回 null。我意识到我一定在做一些愚蠢的事情,但无法弄清楚。
谁能帮忙?
【问题讨论】:
-
你是如何锁定/同步的?因为你更清楚自己在做什么。我从来不需要绕过
managed_mapped_file级别的锁定 -
@sehe 如果我不使用空互斥锁,我根本无法让它工作;执行 find_or_construct
(unique_instance)() 有效,但随后在另一个进程中执行 find (unique_instance),即使进程 A 已终止,它也会挂起等待互斥锁(在 priv_generic_find 中)! -
平台、库/编译器版本是什么?
-
这是问题所在 - 请参阅下面接受的答案
标签: c++ boost boost-interprocess