Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Assuming you are developing this in DevStudio, you can get the control you want using [IO Completion Ports]. Scary name, for a simple tool.</p> <ul> <li>First, create an IOCompletion Port: <a href="http://msdn.microsoft.com/en-us/library/aa363862(VS.85).aspx" rel="noreferrer">CreateIOCompletionPort</a></li> <li>Create your pool of worker threads using _beginthreadex / CreateThread</li> <li>In each worker thread, implement a loop that calls <a href="http://msdn.microsoft.com/en-us/library/aa364986(VS.85).aspx" rel="noreferrer">GetQueuedCompletionStatus</a> - The returned lpCompletionKey will be pointing to a work item to process.</li> <li>Now, whenever you get a work item to process: call <a href="http://msdn.microsoft.com/en-us/library/aa365458(v=VS.85).aspx" rel="noreferrer">PostQueuedCompletionStatus</a> from any thread - passing in the pointer to your work item as the completion key parameter.</li> </ul> <p>Thats it. 3 API calls and you have implemented a thread pooling mechanism based on a kernel implemented queue object. Each call to PostQueuedCompletionStatus will automatically be deserialized onto a thread pool thread thats blocking on GetQueuedCompletionStatus. The pool of worker threads is created, and maintained - by you - so you can call TerminateThread on any worker threads that are taking too long. Even better - depending on how it is set up the kernel will only wake up as many threads as needed to ensure that each CPU core is running at ~100% load.</p> <p>NB. TerminateThread is really not an appropriate API to use. Unless you really know what you are doing the threads are going to leak their stacks, none of the memory allocated by code on the thread will be deallocated and so on. TerminateThread is really only useful during process shutdown. There are some articles on the net detailing how to release the known OS resources that are leaked each time TerminateThread is called - if you persist in this approach you really need to find and read them if you haven't already.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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