Differences between revisions 3 and 4
Revision 3 as of 2014-06-03 06:42:01
Size: 1211
Editor: HungTa
Comment:
Revision 4 as of 2014-06-03 06:42:47
Size: 1213
Editor: HungTa
Comment:
Deletions are marked like this. Additions are marked like this.
Line 16: Line 16:

{{{#!highlight cpp
Line 18: Line 21:

{{{#!highlight cpp

The Thread Pool

Thread Pools are useful when you need to limit the number of threads running in your application at the same time. There is a performance overhead associated with starting a new thread, and each thread is also allocated some memory for its stack etc.

Instead of starting a new thread for every task to execute concurrently, the task can be passed to a thread pool. As soon as the pool has any idle threads the task is assigned to one of them and executed. Internally, the thread pool handle has to be created first, then the tasks are inserted into this handle and executed.

Thread pools are often used in multi threaded servers. Each connection arriving at the server via the network is wrapped as a task and passed on to a thread pool. The threads in the thread pool will process the requests on the connections concurrently.

Implementation

The Thread Pool is a client library that is linked with every component that uses it.

#include <clThreadPool.hxx>

APIs

   1 // Definition of user task
   2 typedef uint32_t (*CallbackT) (void* invocation);
   3 
   4 class Callable
   5   {
   6   public:
   7     run(CallbackT* fn)
   8 
   9     
  10   };

SAFplus: ThreadPool (last edited 2014-06-04 18:42:59 by AndrewStone)