Boost logo

Boost Users :

Subject: Re: [Boost-users] [ASIO] How to terminate a io_service inside a library.
From: Daniele Barzotti (daniele.barzotti_at_[hidden])
Date: 2009-04-10 08:43:25


Igor R wrote:
>
> I think the best way to do this is to remove the "work" object when
> you want the io_service's thread(s) to end. So, if you wish this to
> happen on last MyObj destruction, I guess the most intuitive approach
> would be to create "work" on the heap and give each MyObj a shared_ptr
> to it - then everything would happen automatically.
> The only concern here is the fact that "work" is destroyed (and thus
> detached from the io_service) in a thread other than io_service's one.
> But since io_service is stated to be thread-safe, I guess it should be
> safe.

Thanks a lot Igor.
Only one thing.. Is there a way to retrieve a work object from the
io_service?

Now I done it like:

EXTERN_C EUROATLIB_API MyObjHandl CALL GetMyObj()
{
  ...
  p_work = new boost::asio::io_service::work(io_service);
  // create the new object
  MyObj pMyObj = new MyObj(io_service);
  pMyObj->io_work_ptr = p_work;
  return pMyObj;
}

But I would like to hide the assignment doing it automatically inside my
MyObj which take an io_service ref in the constructor.

Thanks!
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