Boost logo

Boost Users :

Subject: [Boost-users] [ASIO] Access violation on io_service::work destructor
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2010-09-23 04:51:14


Hi,

In my code I have a io_Service and a work object shared among my classes:

// Main io_service
static boost::asio::io_service io_service;
static boost::scoped_ptr<boost::thread> io_service_thread;
static boost::asio::io_service::work* p_work;
static BOOL thread_started;

void io_worker_thread(void)
{

#if(WIN32 && _WIN32_DCOM)
  struct com_init
  {
    com_init() { CoInitializeEx(NULL, COINIT_APARTMENTTHREADED); }
    ~com_init() { CoUninitialize(); }
  } initializer_object;
#endif

  io_service.run();
  io_service.reset();
  thread_started = false;
};

void Init(....)
{
  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:
      // Instead of start the worker thread directly
      // by passing the io_service object,
      // I call the io_worker_thread function where
      // I can do some initialization tasks like
      // calling CoInitializeEx for COM
      io_service_thread.reset(new boost::thread(io_worker_thread));

      thread_started = !thread_started;

    } catch (boost::thread_resource_error e) {
      // Failed to create the new thread
      return 0;
    }
  }
}

When my application ends and the io_service.run() returns I get:

First-chance exception at 0x09299c18 (AxEuroATLib_debug.dll) in
EuroSvr.exe: 0xC0000005: Access violation reading location 0xf0f0f0fc.

at the following line (io_service.ipp):

inline io_service::work::~work()
{
  io_service_.impl_.work_finished();
}

I wrong something?

Regards,
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