locked
How many threads will be created during RegisterWaitForSingleObject RRS feed

  • Question

  • If i have 70 processes handles and RegisterWaitForSingleObject is called each of them. As per observation, it created 70 threads when 70 processes are terminated. But those threads are not exiting even if UnRegisterWait() is invoked. Sample code is below

    RegisterWaitForSingleObject(&pDlg->m_OutHandle,pThread->m_hThread,WaitCallback, reinterpret_cast<void*>( nIdx ),                                     INFINITE, WT_EXECUTEONLYONCE );
    
    UnregisterWait( m_OutHandle );


    Thanks, Renjith V R

    Thursday, June 4, 2015 5:35 AM

All replies

  • The callback is invoked on a threadpool thread. I suppose it's possible that if all processes are terminated in a small window of time and those wait callbacks are relatively slow (do you have any code in the callback other than UnregisterWait?) the threadpool will balloon to 70 threads. And threadpool threads don't exist instantly, they stick around for a while in case there's more threadpool work to be done.

    Are you concerned by the number of thread? I'd be more concerned with the number of processes :)

    Thursday, June 4, 2015 6:18 AM

  • Are you concerned by the number of thread? I'd be more concerned with the number of processes :)

    It is a sample application. Actually, i need to capture the abnormal termination of process. The no of process may exceed 64. So WaitForMulitpleObect will be failed. I need to solve this issue. I think the thread is created only when the call back is invoked.

    I am trying to handle it by waiting fro multiple thread. In that case each thread can keep 64 handle and the thread count can be reduced.


    Thanks, Renjith V R

    Thursday, June 4, 2015 2:25 PM
  • "I think the thread is created only when the call back is invoked."

    Yes, if a threadpool isn't already available.

    "I am trying to handle it by waiting fro multiple thread. In that case each thread can keep 64 handle and the thread count can be reduced."

    It seems to me that instead you should continue to use RegisterWaitForSingleObject and investigate why you end up with 70 threads. That's not normal and it doesn't happen in a quick test program I wrote.

    Thursday, June 4, 2015 2:31 PM