Boost logo

Boost Users :

Subject: [Boost-users] boost::interprocess::message_queue::timed_receive, bug or mistake?
From: nacitar_at_[hidden]
Date: 2009-01-23 18:45:34


I'm using boost svn 50746 (latest at time of writing), on 32-bit
Ubuntu Intrepid Ibex, with gcc/g++ 4.3.2

This is a simple test case showing that for some reason,
message_queue::timed_receive is returning immediately for me, not
throwing an exception, but just returning false which signifies that
the timeout has been reached.

The output of the program is as follows:
Current time: 2009-Jan-23 17:40:29
After delay: 2009-Jan-23 17:40:34
Timeout at 2009-Jan-23 17:40:29

Note that the timeout occurs before it is supposed to, it returns instantly.

Is this a bug, or am I doing something wrong?

MINIMAL CODE:

#include <iostream>
#include <boost/interprocess/ipc/message_queue.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
// Link with boost_date_time
int main(void)
{
        char buf[1024];
        std::size_t uSize;
        unsigned int priority;

        // Create a queue
        boost::interprocess::message_queue::remove("SOME_QUEUE");
        boost::interprocess::message_queue
mq(boost::interprocess::create_only,"SOME_QUEUE",1024,1024);

        // 5 second delay
        boost::posix_time::time_duration delay(boost::posix_time::seconds(5));
        // current time
        boost::posix_time::ptime timeout =
boost::posix_time::ptime(boost::posix_time::second_clock::local_time());

        std::cout << "Current time: " <<
boost::posix_time::to_simple_string(timeout) << std::endl;
        timeout += delay;
        std::cout << "After delay: " <<
boost::posix_time::to_simple_string(timeout) << std::endl;

        if (mq.timed_receive(buf,sizeof(buf),uSize,priority,timeout))
        {
                std::cout << "Got a message!" << std::endl;
        }
        else
        {
                std::cout << "Timeout at " <<
boost::posix_time::to_simple_string(boost::posix_time::ptime(boost::posix_time::second_clock::local_time()))<<
std::endl;
        }
        return 0;
}


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