问题
Currently I have two standalone C++ programs, a master and a slave. The master writes some data to shared memory, using boost::interprocess
, and then launches the slave, which is able to read from the memory.
What I would like to do is to have the slave constantly running, and for the master to send a message to the slave when the memory has been written to and is ready to be read from.
The only way I can think to achieve the same thing is for the slave to constantly check the shared memory for the presence of an object, and when it is detected read from it and delete it. However, this doesn't seem optimal.
Is there a nicer way of achieving the same thing?
Background: This is a continuation of my previous question here...
回答1:
You can use posix message queues, or better yet boost message queues.
回答2:
Why not have them communicate over a unix domain socket? From the other question, you said you were building this on ubuntu, so that won't work immediately on windows.
Boost has support for this in the boost::asio lib, which I suspect uses named pipe sockets when you compile for windows.
来源:https://stackoverflow.com/questions/8900141/message-passing-between-two-programs