Boost logo

Boost :

From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-05-08 10:41:49


When we have to create lot of threads dynamicaly it will be better to have a
'pool' of initialized threads (the initialization of a thread takes
significant time). Please not that this has nothing to be with the
thread_pool class.

I'm looking for any work done related to this problem (libraries, emails,
Any hints or comments?

Thanks in advance


My first thoghts:
The cached_threader class interface could be something like

class cached_thread;

class cached_threader {
    cached_thread launch(boost::function<void()>&);
    friend class cached_thread;
    void restore(cached_thread);

cached_thread will provide most of the boost::thread operation but some as
detach seams not adapted.
class cached_thread
    friend class cached_threader;
    cached_threade launch(boost::function<void()>& f);


    // move support
    cached_thread(detail::thread_move_t<thread> x);
    cached_thread& operator=(detail::thread_move_t<cached_thread> x);
    operator detail::thread_move_t<cached_thread>();
    detail::thread_move_t<cached_thread> move();

    void swap(cached_thread& x);

    // ...

The destructor has the responsability to restore the cached_thread to its
cached_threader pool.

Vicente Juan Botet Escriba

Boost list run by bdawes at, gregod at, cpdaniel at, john at