$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [asio] need help with timer crash please
From: Igor R (boost.lists_at_[hidden])
Date: 2009-03-27 05:36:33
> Thanks for the reply.  However, I've confirmed that the
> boost::asio::deadline_timer object still exists.
The timer object exists, but what about the objects which are accessed
from the handler? Can you post some code snippet?
> In examples I've found for repeating timers, that the timer is re-scheduled
> within the handler itself.  In my case, the timer is re-scheduled sometime after
> the handler has run.  I wonder if a timer cannot be re-used this way?
The timer can be used in any way, until you don't try to access it
simultaneously from multiple threads.
> One additional bit of information is that the timer is scheduled for the very
first time by the main process, before the worker thread enters
io_service::run().  Is there any problem with scheduling a timer with one thread
and then re-scheduling it with another?
If you mean something like this:
int main()
{
  io_service io;
  deadline_timer timer(io);
  timer.expires(...);
  timer.async_wait(...);
  thread t(&io_service::run, &io);
  t.join();
};
then it's ok, because there's no race conditions here: when you access
the timer from the main thread, the timer is not running.