|
-
May 26th, 2005, 01:11 AM
#1
Thread Pooling
Hi,
I want to implement thread pooling for my multi threaded MFC application.
At present, my application creates one thread for each request. It slow downs the system. So I want queue the requests and then process them using some constant no of threads.
Regards
MJV
-
May 26th, 2005, 01:35 AM
#2
Re: Thread Pooling
Create some threads lets say 'n'
Make them wait on a queue.
Add the data to the queue and signal the event of the threads.
Let Each thread get the elements from the queue.
Provide Syncronization for the Queue data.
Do Not kill the threads if NO DATA retreived from the queue.
Ritesh Tandon
(Sr. Software Engineer)
-
May 26th, 2005, 01:45 AM
#3
Re: Thread Pooling
Hi,
thanks for the inforamtion. can somebody post some small sample code???
-
May 26th, 2005, 01:56 AM
#4
Re: Thread Pooling
If you are running on Windows NT (Win2K, XP or higher), consider using the builtin win32 thread pool mechanism: QueueUserWorkItem().
Arjay
-
May 26th, 2005, 04:42 AM
#5
-
May 26th, 2005, 04:44 AM
#6
Re: Thread Pooling
 Originally Posted by mjvalan
Hi,
I want to implement thread pooling for my multi threaded MFC application.
At present, my application creates one thread for each request. It slow downs the system. So I want queue the requests and then process them using some constant no of threads.
Regards
MJV
"One thread per request" may not be appropriate depending on what you mean by request. The process of swapping from one thread to another is known as a context switch. Too many of those happening continually will eat up the CPU time.
If your threads do any kind of IO including IO using sockets, windows has a set of APIs that control something called a completion port. These provide a much more efficient technique than multithreading.
There is quite a good article about this technique here:
http://www.sysinternals.com/ntw2k/info/comport.shtml
Markus
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|