【发布时间】:2015-07-29 09:23:08
【问题描述】:
我想使用 boost interprocess 在不同平台之间进行通信。
我在 Windows 7 上使用 vc12 和 boost 1.58。
我下面的代码是一个非常简单的示例,应该可以工作。但它不适用于不同平台之间的通信......
如果我在 x64 中创建 msm 并在 win32 中打开,则进程卡在 boost/int/sync/detail/common_algorithms.hpp 中函数 try_based_lock 处的锁定
反过来:win32 创建,x64 打开:进程在 segment_manager_helper.hpp 中的 name_length 处崩溃,同时尝试在索引中查找名称(segment_manager 中的 priv_generic_find)。
问题出现在 msm.find("Data")
#include <iostream>
#include <boost/interprocess/managed_shared_memory.hpp>
int main() {
namespace bip = boost::interprocess;
// open in WIN32, create in x64
#ifndef _WIN64
bip::managed_shared_memory msm(bip::open_only, "TestIPC");
#else
bip::shared_memory_object::remove("TestIPC");
bip::managed_shared_memory msm(bip::create_only, "TestIPC", 4096);
msm.construct<uint32_t>("Data")[1](10);
#endif
// Get Data and print it
auto data = msm.find<uint32_t>("Data");
if (data.second == 1) {
std::cout << *data.first << std::endl;
}
std::cin.ignore();
return 0;
}
有人有这方面的经验吗?
【问题讨论】:
-
您 should not 未定义 _WIN32。这可能会影响 boost 库。
标签: c++ boost platform interprocess boost-interprocess