Boost logo

Boost Users :

Subject: Re: [Boost-users] access violation with asio
From: Igor R (boost.lists_at_[hidden])
Date: 2011-08-02 09:53:59


> can anybody explain me please why I get an access violation in the following
> code?
> And why if I enable the std::cout in the stream_handler destructor the code
> work fine without exception?

Because you've got a race condition between stream_handler (and its
private io_service) destruction, which occurs in the main thread, and
the internal io_service shut-down process, which occurs in the thread
that invokes io_service::run().
std::cout just take long enough to affect this race contdition.

To solve the problem, add thread.join() to the destructor.


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