[Boost-bugs] [Boost C++ Libraries] #4749: Problem with deadline_timer on MacOSX

Subject: [Boost-bugs] [Boost C++ Libraries] #4749: Problem with deadline_timer on MacOSX
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-10-18 08:10:42


#4749: Problem with deadline_timer on MacOSX
-------------------------------------+--------------------------------------
 Reporter: jc_monnin@… | Owner: chris_kohlhoff
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: asio
  Version: Boost 1.44.0 | Severity: Problem
 Keywords: |
-------------------------------------+--------------------------------------
 When multiple threads call io_service::run() and there is one active
 deadline_timer, deadline_timer takes much more time to invoke the handler
 that specified.[[BR]]

 This has been observed on MacOSX 10.6, XCode 3.2.2 using the test
 application posted below. The time between the 1st and 2nd invoke of
 "print1" is almost 5 minutes instead of 1 second.[[BR]]

 It runs fine on Windows and Linux and when defining
 BOOST_ASIO_DISABLE_KQUEUE, the problem disappears on MacOSX.

 {{{
 #include <iostream>
 #include <boost/asio.hpp>
 #include <boost/thread.hpp>
 #include <boost/bind.hpp>
 #include <boost/date_time/posix_time/posix_time.hpp>

 class printer
 {
 public:
         printer(boost::asio::io_service& io)
         : strand_(io),
         timer1_(io, boost::posix_time::seconds(1)),
         count_(0)
         {
 timer1_.async_wait(strand_.wrap(boost::bind(&printer::print1, this)));
         }

         ~printer()
         {
                 std::cout << "Final count is " << count_ << "\n";
         }

         void print1()
         {
                 if (count_ < 10)
                 {
                         std::cout << "Timer 1: " << count_ << "\n";
                         ++count_;

                         timer1_.expires_at(timer1_.expires_at() +
 boost::posix_time::seconds(1));
 timer1_.async_wait(strand_.wrap(boost::bind(&printer::print1, this)));
                 }
         }

 private:
         boost::asio::strand strand_;
         boost::asio::deadline_timer timer1_;
         int count_;
 };

 int main()
 {
         boost::asio::io_service io;
         printer p(io);
         boost::thread t(boost::bind(&boost::asio::io_service::run, &io));
         io.run();
         t.join();

         return 0;
 }
 }}}

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4749>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:04 UTC