https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=a951054d992dbd379c2336101515fd9e8ad8a882
commit a951054d992dbd379c2336101515fd9e8ad8a882 Author: Takashi Yano <[email protected]> AuthorDate: Mon Nov 25 19:51:53 2024 +0900 Commit: Corinna Vinschen <[email protected]> CommitDate: Fri Dec 6 11:30:09 2024 +0100 Cygwin: signal: Fix deadlock between main thread and sig thread Previously, a deadlock happened if many SIGSTOP/SIGCONT signals were received rapidly. If the main thread sends __SIGFLUSH at the timing when SIGSTOP is handled by the sig thread, but not is handled by the main thread yet (sig_handle_tty_stop() not called yet), and if SIGCONT is received, the sig thread waits for cygtls::current_sig (is SIGSTOP now) cleared. However, the main thread waits for the pack.wakeup using WaitForSingleObject(), so the main thread cannot handle SIGSTOP. This is the mechanism of the deadlock. This patch uses cygwait() instead of WaitForSingleObject() to be able to handle the pending SIGSTOP. Addresses: https://cygwin.com/pipermail/cygwin/2024-November/256744.html Fixes: 7759daa979c4 ("(sig_send): Fill out sigpacket structure to send to signal thread rather than racily sending separate packets.") Reported-by: Christian Franke <[email protected]> Reviewed-by: Corinna Vinschen <[email protected]> Signed-off-by: Takashi Yano <[email protected]> (cherry picked from commit d243e51ef1d30312ba1e21b4d25a1ca9a8dc1f63) Diff: --- winsup/cygwin/sigproc.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index a758bc8f2c05..2e813b3a7e77 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -760,7 +760,7 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls) if (wait_for_completion) { sigproc_printf ("Waiting for pack.wakeup %p", pack.wakeup); - rc = WaitForSingleObject (pack.wakeup, WSSC); + rc = cygwait (pack.wakeup, WSSC); ForceCloseHandle (pack.wakeup); } else
