Igor R ha scritto:
io_service.run(); Put some debug message here, to see when the io_service::run ends.
Hi Igor, thanks for you reply. I've put some debug code: ---------------------- START CODE ------------------------ void io_worker_thread(void) { io_service.run(); std::cout << ">>>> io_service.run() TERMINATED! <<<<" << endl; }; ---------------------- END CODE ------------------------ And the io_service.run() never returns, neither at the end of the application. This was caused because I had declared the io_service::work* like a shared_ptr. I change its declaration to simply: static boost::asio::io_service::work* p_work; And now io_service.run() ends only at the application end. So, when I call the timer, the io_service should run!! I try to add a call to io_service.run() after the timer async_wait: ---------------------- START CODE ------------------------ { ..... //Start a new timer or renew it rx_timer_.expires_from_now( boost::posix_time::milliseconds( 2000 ) ); // We managed to cancel the timer. Start new asynchronous wait. rx_timer_.async_wait( boost::bind(&WaveStream::handle_timeout, this, _1) ); io_service.run(); std::cout << "io_service.run() called " << endl; } void WaveStream::handle_timeout(const boost::system::error_code& error) { std::cout << "BOOST TIMER RAISED!!" << endl; }; ---------------------- END CODE ------------------------ ..and in this manner the callback is called immediately after the io_service.run() without waiting and in output I see: BOOST TIMER RAISED!! io_service.run() called BOOST TIMER RAISED!! io_service.run() called BOOST TIMER RAISED!! io_service.run() called BOOST TIMER RAISED!! io_service.run() called BOOST TIMER RAISED!! Suggestions? Daniele.