Terminate long running thread in thread pool that was created using QueueUserWorkItem(win 32/nt5).

Posted by Jake on Stack Overflow See other posts from Stack Overflow or by Jake
Published on 2010-05-03T03:05:45Z Indexed on 2010/05/03 3:18 UTC
Read the original article Hit count: 410

Filed under:
|
|
|

I am programming in a win32 nt5 environment.

I have a function that is going to be called many times. Each call is atomic. I would like to use QueueUserWorkItem to take advantage of multicore processors.

The problem I am having is I only want to give the function 3 seconds to complete. If it has not completed in 3 seconds I want to terminate the thread.

Currently I am doing something like this:

HANDLE newThreadFuncCall= CreateThread(NULL,0,funcCall,&func_params,0,NULL); DWORD result = WaitForSingleObject(newThreadFuncCall, 3000); if(result == WAIT_TIMEOUT) { TerminateThread(newThreadFuncCall,WAIT_TIMEOUT); }

I just spawn a single thread and wait for 3 seconds or it to complete. Is there anyway to do something similar to but using QueueUserWorkItem to queue up the work?

Thanks!

© Stack Overflow or respective owner

Related posts about win32

Related posts about c++