The current code waits for `sendsig` by `for` loop in sigproc.cc,
however, the wait time might be insufficient for recent CPU.
The current code is as follows.

   for (int i = 0; !p->sendsig && i < 10000; i++)
     yield ();

Due to this problem, in tcsh, the following command occasionally
cannot be terminated by Ctrl-C. This is because, SIGCONT does not
wake-up `sleep` process correctly.

  $ cat | sleep 100 &
  $ fg
  $ (type Ctrl-C)

With this patch, the wait time for `sendsig` is guaranteed to be
up to 100ms instead of looping for 10000 times.

Fixes: d584454c8231 ("* sigproc.cc (sig_send): Wait for dwProcessId to be 
non-zero as well as sendsig.")
Signed-off-by: Takashi Yano <[email protected]>
Reviewed-by:
---
 winsup/cygwin/sigproc.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc
index 30779cf8e..0fd7ed3ba 100644
--- a/winsup/cygwin/sigproc.cc
+++ b/winsup/cygwin/sigproc.cc
@@ -646,7 +646,8 @@ sig_send (_pinfo *p, siginfo_t& si, _cygtls *tls)
     {
       HANDLE dupsig;
       DWORD dwProcessId;
-      for (int i = 0; !p->sendsig && i < 10000; i++)
+      DWORD t0 = GetTickCount ();
+      while (GetTickCount () - t0 < 100 && !p->sendsig)
        yield ();
       if (p->sendsig)
        {
-- 
2.51.0

Reply via email to