好日子伙计,64位和32位进程互通boost :: message_queue
我目前正试图想象一种方式来传递64位进程和32位进程之间的数据。由于它是一个实时应用程序,并且两者都在同一台计算机上运行,所以我使用共享内存(shm)很难。
虽然我正在寻找一些使用shm的同步机制,但我在boost :: message_queue上感受到了。但它不起作用。
我的代码基本上是以下几点:
发件人部分
message_queue::remove("message_queue");
message_queue mq(create_only, "message_queue", 100, sizeof(uint8_t));
for (uint8_t i = 0; i < 100; ++i)
{
mq.send(&i, sizeof(uint8_t), 0);
}
接收器部分
message_queue mq(open_only, "message_queue");
for (uint8_t i = 0; i < 100; ++i)
{
uint8_t v;
size_t rsize;
unsigned int rpriority;
mq.receive(&v, sizeof(v), rsize, rpriority);
std::cout << "v=" << (int) v << ", esize=" << sizeof(uint8_t) << ", rsize=" << rsize << ", rpriority=" << rpriority << std::endl;
}
此代码工作完全如果这两个过程是64位或32位。但如果这两个过程不一样,则不起作用。
升压寻找更深(1.50.0)的代码,你会看到在message_queue_t以下行:: do_receive(升压/间/ IPC/message_queue.hpp):
scoped_lock lock(p_hdr->m_mutex);
出于某种原因,在当处理异构进程时,互斥锁似乎被锁定。我疯狂的猜测是互斥体被抵消了,因此它的价值被破坏了,但我不太确定。
我想完成一些根本不支持的功能吗?
任何帮助或建议将不胜感激。
这不是一个疯狂的猜测,这是准确的。他们把互斥量放在共享内存中,并且它的大小取决于位数。你无法完成这项工作。 – 2012-08-11 19:10:01