Boost message_queue: when I receive an object, how can I remove it from the queue?

I noticed that, when I get an object from a Boost message_queue with the *receive() member functions, that object remains in the queue. So if I read the same message_queue multiple times, I keep getting copies of the same objects, even if nothing has been inserted from the producer's side. Is there a way to remove an object from the queue once it has been read? In message_queue I found no member function that allows to do it. E.g.: (this is pseudo code; the consumer is shown and the producer would be in a separate process) boost::scoped_ptrboost::interprocess::message_queue pMQueue; message_queue::remove("myQueue"); pMQueue.reset(new message_queue(open_or_create, "myQueue", 100, sizeof(MyClass))); MyClass token; std::vector<MyClass> tokens; size_t recvdSize = 0; float timeDelay = 100; // milliseconds bool dataAvailable = true; // If I do this block twice, I receive the same tokens twice while(dataAvailable) { ptime t = microsec_clock::universal_time() + milliseconds(timeDelay); dataAvailable = pMQueue->timed_receive(&token, sizeof(token), recvdSize, 0, t); if(dataAvailable && recvdSize > 0) tokens.push_back(token); else ... } Note: in this example, MyClass' objects are fixed sized POD member variable objects only. -- View this message in context: http://boost.2283326.n4.nabble.com/Boost-message-queue-when-I-receive-an-obj... Sent from the Boost - Users mailing list archive at Nabble.com.

Ops, I found a bug in my code. The message_queue works as expected, the problem was in the way the tokens container was managed. -- View this message in context: http://boost.2283326.n4.nabble.com/Boost-message-queue-when-I-receive-an-obj... Sent from the Boost - Users mailing list archive at Nabble.com.
participants (1)
-
pietro