[newlib-cygwin/cygwin-3_5-branch] Cygwin: signal: Increase chance of handling signal in main thread

Corinna Vinschen corinna@sourceware.org
Fri Dec 6 10:47:38 GMT 2024


https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=7adfc92401cb00b9a59b25a792a5d5f6dc1220a6

commit 7adfc92401cb00b9a59b25a792a5d5f6dc1220a6
Author:     Takashi Yano <takashi.yano@nifty.ne.jp>
AuthorDate: Tue Dec 3 22:14:44 2024 +0900
Commit:     Corinna Vinschen <corinna@vinschen.de>
CommitDate: Fri Dec 6 11:42:48 2024 +0100

    Cygwin: signal: Increase chance of handling signal in main thread
    
    If the process() fails and the signal remains in the queue, the most
    possible reason is that the target thread is already armed by another
    signal and does not handle it yet. With this patch, to increase the
    chance of handling it in the other threads, call yield() before
    retrying process().
    
    Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html
    Fixes: e10f822a2b39 ("Cygwin: signal: Handle queued signal without explicit __SIGFLUSH")
    Reported-by: Christian Franke <Christian.Franke@t-online.de>
    Reviewed-by:
    Signed-off-by: Takashi Yano <takashi.yano@nifty.ne.jp>
    (cherry picked from commit c48d58d838d90df6247123c487686699742d75de)

Diff:
---
 winsup/cygwin/sigproc.cc | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 3fe6447e54ff..b9669a861610 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -1325,7 +1325,10 @@ wait_sig (VOID *)
 	pack.si.si_signo = __SIGFLUSH;
       else if (sigq.start.next
 	       && PeekNamedPipe (my_readsig, NULL, 0, NULL, &nb, NULL) && !nb)
-	pack.si.si_signo = __SIGFLUSH;
+	{
+	  yield ();
+	  pack.si.si_signo = __SIGFLUSH;
+	}
       else if (!ReadFile (my_readsig, &pack, sizeof (pack), &nb, NULL))
 	Sleep (INFINITE);	/* Assume were exiting.  Never exit this thread */
       else if (nb != sizeof (pack) || !pack.si.si_signo)


More information about the Cygwin-cvs mailing list