|
Boost : |
From: vicente.botet (vicente.botet_at_[hidden])
Date: 2008-05-08 10:41:49
Hi,
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
Vicente
My first thoghts:
The cached_threader class interface could be something like
class cached_thread;
class cached_threader {
public:
cached_thread launch(boost::function<void()>&);
private:
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);
public:
cached_thread();
~cached_thread();
// 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 acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk