cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Mysterious random crash demystified.

From: Traian Nicolescu <traian_at_burstcopy.com>
Date: Thu, 14 Oct 2004 20:29:10 +0300 (EEST)

> I've added and tested your patch and it looks very good. Haven't found any
> problems yet. But I'm always on the edge when I see things like:
> WaitForSingleObject(td->thread_hnd, INFINITE);
>
> Can we be 100% sure it never blocks indefinetely (waiting for the thread)
> in extreme cases?

I've written it as INFINITE, relying on the following judgements.

1. We know that the thread is no longer blocking. It's signaled our event.
It just has to run the callback and exit.

2. We're waiting for a thread to exit. No matter the way it exits, even if
it crashes, we'll still get signaled that it did.

3. It is difficult to make a definite assumption as to what the timeout
should be in such a scenario. The running process may for example be set
on idle priority. If so, it is possible that it will frequently get little
to no processor time for indefinite amounts of time. Sleep times are
however implemented in real time, and we would timeout even if the thread
never got any processor time to actually callback with the information.

But, I think you're right. That would indeed be an extreme situation and
would justify use of forced thread termination.
------
if( WaitForSingleObject(td->thread_hnd, 5000) == WAIT_TIMEOUT ) {
  TerminateThread( td->thread_hnd );
  /* proceed as failure */
}
------

Best Regards,
Traian Nicolescu.
Received on 2004-10-14