Boost logo

Boost Users :

Subject: Re: [Boost-users] [asio] How to know if the io_service is runing
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-10-14 05:17:15


Daniele Barzotti ha scritto:
> In my library I have this code (yet used in another project) where pwork
> is assigned to a shared_ptr:
> .....
> The timer callback is never called.

I've change the code in this way:

> --------------------------------------------------------------
> typedef boost::shared_ptr<boost::asio::io_service::work> io_work_ptr;
>
> // Main io_service
> static boost::asio::io_service io_service;
> static boost::asio::io_service::work* p_work;

The io_service::work now is stored into a shared_ptr:

static io_work_ptr p_work;

so I'm pretty sure it is running.

> bool CreateMainThread()
> {
> if (!thread_started) {
> try {
> // create the work object on the heap
> p_work = new boost::asio::io_service::work(io_service);

p_work.reset( new boost::asio::io_service::work(io_service) );

--------------------------------------------------------------
WaveStream::WaveStream() : rx_timer_(io_service)
{
};

WaveStream::Test()
{
  io_service.reset();
  //Start a new timer or renew it
  rx_timer_.expires_from_now( boost::posix_time::milliseconds(500) );
  //Start new asynchronous wait.
  rx_timer_.async_wait(
    boost::bind(&WaveStream::handle_timeout, this, _1)
  );
}

void WaveStream::handle_timeout(const boost::system::error_code& error)
{
 ....
}
--------------------------------------------------------------

I don't know why the handler is not called!

Daniele.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net