64-bit and 32-bit technology interoperability: message_queue

Good afternoon,

I'm currently trying to figure out a way to transfer data between a 64-bit process and a 32-bit process. Since this is a real-time application, and both work on the same computer, I use shared memory (shm) hard.

While I was looking for some kind of synchronization mechanism using shm, I felt in boost :: message_queue. However, it does not work.

My code is basically the following:

Sender

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); } 

Recipient

 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; } 

This code works fine if two processes are 64-bit or 32-bit. But it does not work if the two processes do not match.

Looking for deeper code (1.50.0), you will see the following line in message_queue_t :: do_receive (boost / interprocess / ipc / message_queue.hpp):

scoped_lock lock (p_hdr-> m_mutex);

For some reason, the mutex seems to be locked out when dealing with heterogeneous processes. My wild guess was that the mutex is biased, and so the meaning is distorted, but I'm not sure.

Am I trying to accomplish something that is simply not supported?

Any help or advice would be appreciated.

+6
source share
2 answers

I think this is about the offset_ptr portability used in message_queue to point to every message, including the header mutex. 32- / 64-bit compatibility should be supported with Boost 1.48.0, as described in https://svn.boost.org/trac/boost/ticket/5230 .

Following the ticket offer, the following definition (so far) worked fine for me in leiu message_queue:

 typedef message_queue_t< offset_ptr<void, int32_t, uint64_t> > interop_message_queue; 

In Boost 1.50.0 in MSVC, this also requires a small patch in message_queue.hpp to resolve template ambiguity: selecting arguments when calling ipcdetail :: get_rounded_size (...).

+5
source

I spent the whole work day finding a solution, and finally I earned it. The solution was partially provided by James, so I used interop_message_queue for both 32-bit and 64-bit processes.

 typedef boost::interprocess::message_queue_t< offset_ptr<void, boost::int32_t, boost::uint64_t>> interop_message_queue; 

The problem is that the code will not compile with this modification, so I also had to add the following, which I found in the list of boost error reports ( # 6147: message_queue sample cannot be compiled in 32-bit format ), this code should be posted before boost includes message_queue:

 namespace boost { namespace interprocess { namespace ipcdetail { //Rounds "orig_size" by excess to round_to bytes template<class SizeType, class ST2> inline SizeType get_rounded_size(SizeType orig_size, ST2 round_to) { return ((orig_size-1)/round_to+1)*round_to; } } } } 
+1
source

Source: https://habr.com/ru/post/922634/


All Articles