Boost logo

Boost :

Subject: Re: [boost] Interest in an Active Object CRTP "decorator"?
From: Dean Michael Berris (mikhailberis_at_[hidden])
Date: 2008-11-10 03:00:44


Hi Oliver!

On Mon, Nov 10, 2008 at 3:49 PM, Oliver Kowalke <k-oli_at_[hidden]> wrote:
>> Thanks for the insights, any interest in seeing something like this in Boost?
>
> Yes - at least I'm interessted in.
> io_service seams to be a queue for work-items - how is it used in the case of threadpool policy (threadpools usally have also an internal queue).
>

I have done this before (using asio::io_service run by a pool of
threads), and something like this would do it:

template <unsigned N>
struct thread_pool {
  protected:
    typedef shared_ptr<thread_group> thread_type;
    void init_threading(thread_type t, shared_ptr<io_service> q) {
      t.reset(new thread_group());
      for (unsigned i=0; i < N; ++i)
        t->create_thread(bind(&io_service::run, q));
    }
    void destroy_threading(thread_type t) {
      t->join_all();
    };
    function<void()> wrap(function<void()> f) {
      return f;
    };
};

Of course, this assumes that functions 'wrapped' would do their own
synchronization (or perhaps use a strand to make sure operations that
do get scheduled will execute accordingly).

HTH!

-- 
Dean Michael C. Berris
Software Engineer, Friendster, Inc.

Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk