difficult SIGCHLD / pipe hang

Joe Buehler jbuehler@hekimian.com
Mon Mar 31 20:41:00 GMT 2003


Is there a bug in the following code in exceptions.cc?  The code can get the winapi_lock
but break out of the loop before releasing it:

	  if (!mainthread.get_winapi_lock (1))
	    continue;

	  hth = myself->getthread2signal ();
	  th = NULL;

	  /* Suspend the thread which will receive the signal.  But first ensure that
	     this thread doesn't have any mutos.  (FIXME: Someday we should just grab
	     all of the mutos rather than checking for them)
	     For Windows 95, we also have to ensure that the addresses returned by GetThreadContext
	     are valid.
	     If one of these conditions is not true we loop for a fixed number of times
	     since we don't want to stall the signal handler.  FIXME: Will this result in
	     noticeable delays?
	     If the thread is already suspended (which can occur when a program has called
	     SuspendThread on itself then just queue the signal. */

	  EnterCriticalSection (&mainthread.lock);
	  sigproc_printf ("suspending mainthread");
	  res = SuspendThread (hth);
	  /* Just release the lock now since we hav suspended the main thread and it
	     definitely can't be grabbing it now.  This will have to change, of course,
	     if/when we can send signals to other than the main thread. */
	  LeaveCriticalSection (&mainthread.lock);

	  /* Just set pending if thread is already suspended */
	  if (res)
	    {
	      (void) ResumeThread (hth);
	      break;
	    }

	  mainthread.release_winapi_lock ();

Also, with regards to the "break", is it safe to resume the thread before setting
the pending flag?
-- 
Joe Buehler



More information about the Cygwin-developers mailing list