< Previous by Date Date Index Next by Date >
< Previous in Thread Thread Index  

Re: [reSIProcate-users] ThreadIf


I think the code checking for STILL_ACTIVE does not seems very obvious at first, but it probably remedies the following situation:

 

If the thread is terminated and the thread handle is already closed, WaitForSingleObject() has an indefinite behavior according to the documentation. I suppose it simply will never return (be it never or just sometimes).

When you call GetExitCodeThread() with an invalid thread handle you will not get the STILL_ACTIVE result and that’s probably why this code works.

 

I suppose a more obvious way would be to check if the return value of GetExitCodeThread() is some kind of ‘invalid handle’ error but that wouldn’t make much difference practically…

 

Matthias Moetje

 

 

 

 

 

From: resiprocate-users-bounces@xxxxxxxxxxxxxxx [mailto:resiprocate-users-bounces@xxxxxxxxxxxxxxx] On Behalf Of Karlsson
Sent: Freitag, 24. Februar 2012 14:13
To: resiprocate-users@xxxxxxxxxxxxxxx
Subject: [reSIProcate-users] ThreadIf

 

In the threadIf.cxx, I think below code is not necessary:    

 

DWORD exitCode;

   while (true)

   {

      if (GetExitCodeThread(mThread,&exitCode) != 0)

      {

         if (exitCode != STILL_ACTIVE)

         {

            break;

         }

         else

         {

            WaitForSingleObject(mThread,INFINITE);

         }

      }

      else

      {

         // log something here

         break;

      }

   }

 

 

 

This is enough:

 

WaitForSingleObject(mThread,INFINITE);