Hi,
2009/9/24 Daniele Barzotti
In my library I have this code (yet used in another project) where pwork is assigned to a shared_ptr:
-------------------------------------------------------------- typedef boost::shared_ptrboost::asio::io_service::work io_work_ptr;
// Main io_service static boost::asio::io_service io_service; static boost::scoped_ptrboost::thread io_service_thread; static boost::asio::io_service::work* p_work; static bool thread_started;
bool CreateMainThread() { if (!thread_started) { try { // create the work object on the heap p_work = new boost::asio::io_service::work(io_service);
// run the IO service as a separate thread: io_service_thread.reset ( new boost::thread ( boost::bind ( &boost::asio::io_service::run, &io_service ) ) );
thread_started = !thread_started; return true;
} catch (boost::thread_resource_error e) { // Failed to create the new thread return false; } } } --------------------------------------------------------------
WaveStream::WaveStream() : rx_timer_(io_service) { };
WaveStream::Test() { //Start a new timer or renew it rx_timer_.expires_from_now( boost::posix_time::milliseconds(500) );
I'm thinking would that be correct if you call timer after async_wait() ?
// We managed to cancel the timer. Start new asynchronous wait.
have You tried restet io_service in this thread, before putting the query on the queue? io_service.reset() If thats correct from Your businesses logic.
rx_timer_.async_wait( boost::bind(&WaveStream::handle_timeout, this, _1) ); }
void WaveStream::handle_timeout(const boost::system::error_code& error) { .... } --------------------------------------------------------------
The timer callback is never called. Is there a way to know if the io_service is runing?
Daniele.
_______________________________________________ Boost-users mailing list Boost-users@lists.boost.org http://lists.boost.org/mailman/listinfo.cgi/boost-users
cheers P.