Click here to Skip to main content
12,824,299 members (41,118 online)
Click here to Skip to main content
Add your own
alternative version


11 bookmarked
Posted 15 Aug 2004

Improve your server with Thread Pooling

, 15 Aug 2004
Rate this:
Please Sign up or sign in to vote.
This articles explains how to implement thread pooling in applications.


"Many applications create threads that spend a great deal of time in the sleeping state, waiting for an event to occur. Other threads might enter a sleeping state only to be awakened periodically to poll for a change or update status information. Thread pooling enables you to use threads more efficiently by providing your application with a pool of worker threads that are managed by the system. One thread monitors the status of several wait operations queued to the thread pool. When a wait operation completes, a worker thread from the thread pool executes the corresponding callback function." (MSDN 2003).


  1. /MT flag is required.
  2. MFC.


The project is well documented and it contains a simple demonstration. The demonstration displays a pool of two threads and fifteen jobs. You can think of it as fifteen connections if it was a socket server.

In the demo, one thread is stuck for a period of time while the work is not stopped, the other thread keeps on doing the jobs.

Call initialize in order to start the thread pool.

You must declare a callback function which will handle jobs of all threads. It should be like this:

bool ThreadCallback(LONG jobId, LPVOID pParam)

The jobId is an inside counting but you'll need it to remove jobs with the following function:

RemoveJob( LONG jobID )

Good luck!


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

Eran Aharonovich
Software Developer
Australia Australia
Been a programmer since 1999.
Experience in:
.Net, C++, C#, VB, VB.NET, ASP, ASP.NET, DLLs, COM etc.

You may also be interested in...

Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170308.1 | Last Updated 16 Aug 2004
Article Copyright 2004 by Eran Aharonovich
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid