Boost logo

Boost Users :

Subject: Re: [Boost-users] Replacing task_io_service (using io_service with an external threadpool)
From: Acer Yang (yangacer_at_[hidden])
Date: 2012-12-23 02:11:58


On Sat, Dec 22, 2012 at 7:31 PM, Juan Ramírez <juanantonio.ram_at_[hidden]>wrote:

> Hi!
>
> I created a (yet another) threapool library a few month ago and, at my
> company, we are starting to use it widely in different services. Using the
> library has lots of advantages for us, mainly because of it performance
> compared with similar libraries.
>
> The problem we are having is that we are using 'two' different kinds of
> thread pool in the same service:
> * The first one is the one I wrote above, the pool provided by my
> library, which is used to execute by the service to execute long or
> expensive operations.
> * And the second one, is the one created a the network level, where about
> a hundred threads are created in order to attend network requests.
> ** Actually calling new thread(io_service::run, ...)
>
> I wanted to move the thread-handling at the network level to my library,
> so I started to look at documentation about extending boost::asio and
> adapting my library to the io_service requirements. What I want to do now
> is to make the io_service object actually use the threadpool library for
> task execution.
>
> I have taken a look to use_service, add_service, and the
> io_service::service class, and I think I already have a pretty good
> implementation of a 'poor man's adaptor' between my library and boost asio.
>
> The question is, how do I force the io_service object to use my service
> implementation instead of the on provided by
> boost::asio::detail::task_io_service?
>
> I mean, I haven't tested yet but I have no idea about how does the
> io_service know which service should be used in each case.
>
> Do I have to force the removal of task_io_service?
> Do I have to call pool() somewhere or re-implement run() functions?
>
> Thanks in advance
>
> Best Regards
>
> __________
> Saludos!
> Juan
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>

Hi Juan,

According to asio/io_service.hpp, the asio::io_service determines its
impl_type in compile time. Here are source code:

#if defined(BOOST_ASIO_HAS_IOCP)
namespace detail { typedef win_iocp_io_service io_service_impl; }
#else
namespace detail { typedef task_io_service io_service_impl; }
#endif

class io_service : private noncopyable
{
  // ...
  typedef detail::io_service_impl impl_type;
  //...
};

asio internally uses use_service<impl_type> to get an instance of
underlying implementation (task_io_service or win_iocp_io_service). It
looks you need to implement your own io_service class.

Cheers,
Acer.



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