CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6

Thread: Thread Pooling

  1. #1
    Join Date
    Jan 2004
    Location
    Bangalore
    Posts
    53

    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

  2. #2
    Join Date
    Feb 2003
    Location
    Hyderabad
    Posts
    181

    Thumbs up 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)

  3. #3
    Join Date
    Jan 2004
    Location
    Bangalore
    Posts
    53

    Re: Thread Pooling

    Hi,

    thanks for the inforamtion. can somebody post some small sample code???

  4. #4
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Thread Pooling

    If you are running on Windows NT (Win2K, XP or higher), consider using the builtin win32 thread pool mechanism: QueueUserWorkItem().

    Arjay

  5. #5
    Join Date
    May 2000
    Location
    KY, USA
    Posts
    18,652

    Re: Thread Pooling


  6. #6
    Join Date
    May 2005
    Posts
    121

    Re: Thread Pooling

    Quote 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
  •  





Click Here to Expand Forum to Full Width

Featured