Thread Pooling


 
Noviway > Source Code > Thread Pooling
Download source code

Introduction

"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).

Requirements

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

Explanation

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 )
 


NAVIGATION MENU
 
Statistics
TCP/IP Sniffer ( Basic )
Thread Pooling
HTTP Browsing
Winsock - Client & Server
Web Crawler
Binary Search
HTML To XML Converter
 
LATEST NEWS & EVENTS
 
Jul 01, 2009
Statistics - Bug fix. The project has also been converted to VS 2008.
 
May 28, 2009
Still working on the layout. Hag Sameah...
 
SPONSERED LINKS
 
Goldberg & Co - Management consulting be CEOs