Opened 12 years ago

Closed 12 years ago

#4749 closed Bugs (duplicate)

Problem with deadline_timer on MacOSX

Reported by: jc_monnin@… Owned by: chris_kohlhoff
Milestone: To Be Determined Component: asio
Version: Boost 1.44.0 Severity: Problem
Keywords: Cc: samjmill@…

Description

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.

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.

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;
}

Change History (2)

comment:1 by samjmill@…, 12 years ago

Cc: samjmill@… added

I don't see this behavior using asio 1.45, which I believe is Boost 1.43. So this appears to be a regression in Boost 1.44.

comment:2 by chris_kohlhoff, 12 years ago

Resolution: duplicate
Status: newclosed

Duplicate of #4568.

Note: See TracTickets for help on using tickets.