
----- Original Message ----- From: "James Talbut" <James.Talbut@omg3d.com> To: <boost@lists.boost.org> Sent: Friday, May 09, 2008 11:01 AM Subject: Re: [boost] [thread] cache of initialized threads
The Windows Threadpool (from Vista onwards) has quite a lot of features and is very usable, unfortunately prior to Vista it was much more limited and couldn't do tracking of job completion well. Using the threadpool involves a lot of functions calls, mainly for initialising static data (you create a structure and pass it to the function to init). The starting point is here: http://msdn.microsoft.com/en-us/library/ms682456.aspx (though you don't actually have to create a threadpool yourself because there is a default).
When a job is submitted and the pool is busy it 'may' create a new thread, depending on a private algorithm. You use SetThreadpoolCallbackRunsLong to influence this. Bearing in mind that thread creation is expensive (potentially much more so than simply completing a callback) you don't want to use a naiive implementation that always creates new threads (unless you know your jobs are big, which a library can't know).
What the user will do if there is no more idle threads if the thread pool do not create it implicitly? May be resize the pool? Yes, this is not a bad idea, the user could request this creation explicitly with one specific parameter. cached_thread thread_factory::make(Callable& fct); cached_thread thread_factory::make(Callable& fct, force_creation_t&);
Obviously, being as they are Windows functions they aren't C++ specific - the job function has a fixed signature taking a PVOID, for example. If you need to support Windows and pthreads I wouldn't use the windows threadpool, coming up with a suitable abstraction won't be simple - I'd go for something built on top of boost::threads.
Yes, you are right when writing a library on top of the boost thread library. The question should not have the same answer if it the thread library will includes this thread factory. Do you think that it would be interesting to use this native thread pool in this case? Thanks for all Vicente
See here for a sample: http://msdn.microsoft.com/en-us/library/ms686980(VS.85).aspx
HTH.
Jim
-----Original Message----- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of vicente.botet Sent: 09 May 2008 09:48 To: boost@lists.boost.org Subject: Re: [boost] [thread] cache of initialized threads
----- Original Message ----- From: "James Talbut" <James.Talbut@omg3d.com> To: <boost@lists.boost.org> Sent: Friday, May 09, 2008 9:39 AM Subject: Re: [boost] [thread] cache of initialized threads
With a thread cache either the threre is a cached_thread in the pool and we use it to launch the user function, either the chached_threader will crate a new one.
I suspect it's not going to help you much, but this is how the native thread pool behaves on Windows.
Hi Jim,
I don't know Windows at all. This is a good new, we will need only to implement it for posix threads.
Could you give me some pointers?
Thanks,
Vicente
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
________________________________________________________________________ This e-mail, and any attachment, is confidential. If you have received it in error, do not use or disclose the information in any way, notify me immediately, and please delete it from your system. ________________________________________________________________________ _______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost