boost::interprocess::message_queue::timed_receive, bug or mistake?
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; }
nacitar@ubercpp.com wrote:
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
Use universal time instead of local time. Maybe this is not documented, and maybe this might be severe limitation. I've seen that boost::thread uses boost::system_time so maybe Interprocess should go this way. Regards, Ion
Ion Gaztañaga wrote:
Use universal time instead of local time. Maybe this is not documented, and maybe this might be severe limitation. I've seen that boost::thread uses boost::system_time so maybe Interprocess should go this way.
Boost thread's system time is universal time: namespace boost { typedef boost::posix_time::ptime system_time; inline system_time get_system_time() { return boost::date_time::microsec_clock <system_time>::universal_time(); } //... } So I should either document this or use boost thread's system time. Regards, Ion
participants (2)
-
Ion Gaztañaga
-
nacitar@ubercpp.com