Search code examples
multithreadingdesign-patternsthreadpoolmulticore

Thread pooling and multi core systems


Do you think threadpooling design pattern is the way to go for the multi-core future?

A threadpooling library for instance, if used extensively, makes/force the application writer

(1) to break the problem into separate parallel jobs hence promoting (enforcing :) ) parallelism

(2) With abstraction from all the low level OS calls, synchronization etc etc makes programmer's life easier. (Especially for C programmers :) )

I have strong belief its the best way (Or One of the "best" ways :) ) for multi-core future...

So, my question is, am I write in thinking so or I am in some delusion :)

Regards,

Microkernel


Solution

  • Thread pooling is a technique that involves a queue and a number of threads taking jobs from the queue and process them. This is in contrast to the technique of just starting new threads whenever a new task arrives.

    Benefits are that the maximum number of threads is limited to avoid too much threading and that there is less overhead involved with any new task (Thread is already running and takes task. No threat starting needed).

    Whether this is a good design highly depends on your problem. If you have many short jobs that come to your program at a very fast rate, then this is a good idea because the lower overhead is really a benefit. If you have extremely large numbers of concurrent tasks this is a good idea to keep your scheduler from having to do too much work.

    There are many areas where thread pooling is just not helpful. So you cannot generalize. Sometimes multi threading at all is not possible. Or not even desired, as multi threading adds an unpredictable element (race conditions) to your code which is extremely hard to debug.

    A thread pooling library can hardly "force" you to use it. You still need to think stuff through and if you just start one thread... Won't help.