Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Without knowing more about your specific application (ie how long messages take to process etc..) there will be lots of handwaving:</p> <ul> <li><p>Is this managed or unmanaged C++?</p></li> <li><p>Which ThreadPool are you using? </p> <ul> <li>QueueUserWorkItem?</li> <li>Your own pool via CreateIoCompletionPort? </li> <li>Or Vista's SubmitThreadpoolWork?</li> </ul></li> </ul> <p>I think platform is somewhat relevant as the nature of the Thread Pool is important.</p> <p>For example:</p> <p>If you use (<a href="http://msdn.microsoft.com/en-us/library/aa365198(VS.85).aspx" rel="nofollow noreferrer">Completion Ports</a>) for your thread pool (ie CreateIoCompletionPort). You have some control on how many threads run concurrently (and hence on how many total threads are ultimately created). If you set the maximum number of concurrent threads to say 4. Windows will will attempt to only allow 4 threads to run concurrently. If all 4 threads are busy processing and you queue a 5th item then windows will not allow that item to run until one of the 4 if finished (reusing the thread). The only time this rule is broken is when threads are blocked (ie waiting on I/O), then more threads are allowed to run.</p> <p>This is the important thing to understand about Completion Ports, and why platform is relevant. It is very difficult to implement something like this without involving the Kernel. Knowing the difference between busy threads and blocked threads requires access to Thread states. Completion ports are very efficient with respect to number of context switches into the Kernel too.</p> <p><strong>Back to your question:</strong></p> <p>It would seem that you should have one thread to process/dispatch the messages and the message processing is all handled by pushing workers onto a thread pool. Let Completion ports handle the load balancing and concurrency. You message processing loop will never block and can continue to process messages. </p> <p>If the rate of incoming messages far exceeds your ability to process them then you will probably have to pay attention to your queue size and block when it grows too large.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload