Thread Pooling

Norbert Nemec Norbert at Nemec-online.de
Mon Apr 24 03:27:47 PDT 2006


Weren't thread pools mostly a crutch for old systems where creating
threads was expensive? Nowadays, threads are usually lightweight enough
that it is the best strategy to write a program creating plenty of
threads and leave the scheduling completely to the operating system.

So, of course, you could have a function like "scheduleTask", but that
function should simply create a thread and it is to operating systems's
job to schedule this thread for later execution.




Craig Black wrote:
> I am not an expert at using threads, but I have an idea that I would like to 
> present that would perhaps make threading easier.
> 
> Thread pooling is a great way to take advantage of concurrency on multi-core 
> systems.  The number of threads in the pool could be equal to the number of 
> cores in the multi-core system.
> 
> D has a big advantage over C++ because it has nested methods, anonymous 
> methods, and delegates.  Delegates could be used with thread pools so that 
> all the programmer would have to do to start a thread would be to call a 
> method like, say, scheduleTask() and pass it a delegate.  (This could be a 
> nested method, or an anonymous method.)  The thread pool would assign the 
> task to the first thread that is idle.  scheduleTask() could return a handle 
> to a Task object.  The Task handle could be used to test to see if the task 
> is running or finished.
> 
> Comments?
> 
> -Craig 
> 
> 



More information about the Digitalmars-d mailing list