Boost logo

Boost Users :

Subject: [Boost-users] Boost message_queue: when I receive an object, how can I remove it from the queue?
From: pietro (pietrom16_at_[hidden])
Date: 2011-10-07 21:14:13


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_ptr<boost::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-object-how-can-I-remove-it-from-the-queue-tp3884126p3884126.html
Sent from the Boost - Users mailing list archive at Nabble.com.

Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net