To: "K.Nagano" <[email protected]>
Subject: patch 5.5a.8 (was: Patch: vim with multithread-perl(Solaris))
Cc: [email protected]
In-Reply-To: <[email protected]>
Fcc: outbox
From: Bram Moolenaar <[email protected]>
------------

K.Nagano wrote:

> I created a small patch.
> I hope this patch is applied in 5.5a.
> However, I also hope anyone solves this problem by more efficient way....
>
> -----
> Problem:    Compiling with multi-threaded perl in Solaris, suspending by ^Z
>             doesn't work correctly.
>             This is occured because kill(0,SIGSTOP) in Solaris/MT doesn't
>             catch the signal in it.(vim overruns until it is yielded!)
> Solution:   In Solaris/MT, let vim wait for SIGSTOP(by pause()) until it
>             arrives.
> Files:      src/os_unix.c
> -----

This looks like a reasonable solution.  I have one addition: Set the SIGCONT
signal back to its default in reset_signals().  Otherwise a child might not
work correctly.

Here is the "official" patch version:

Patch 5.5a.8
Problem:    On multi-threaded Solaris, suspending doesn't work.
Solution:   Call pause() when the SIGCONT signal was not received after
           sending the SIGTSTP signal. (Nagano)
Files:      src/os_unix.c


*** ../vim-5.5a.7/src/os_unix.c Mon Aug 30 10:40:56 1999
--- src/os_unix.c       Thu Sep  2 12:35:54 1999
***************
*** 573,578 ****
--- 573,599 ----
     SIGRETURN;
 }

+ #ifdef _REENTRANT
+ /*
+  * On Solaris with multi-threading, suspending might not work immediately.
+  * Catch the SIGCONT signal, which will be used as an indication whether the
+  * suspending has been done or not.
+  */
+ static int sigcont_received;
+ static RETSIGTYPE sigcont_handler __ARGS(SIGPROTOARG);
+
+ /*
+  * signal handler for SIGCONT
+  */
+ /* ARGSUSED */
+     static RETSIGTYPE
+ sigcont_handler SIGDEFARG(sigarg)
+ {
+     sigcont_received = TRUE;
+     SIGRETURN;
+ }
+ #endif
+
 /*
  * If the machine has job control, use it to suspend the program,
  * otherwise fake it by starting a new shell.
***************
*** 585,591 ****
--- 606,622 ----
     out_flush();          /* needed to make cursor visible on some systems */
     settmode(TMODE_COOK);
     out_flush();          /* needed to disable mouse on some systems */
+
+ # ifdef _REENTRANT
+     sigcont_received = FALSE;
+ # endif
     kill(0, SIGTSTP);     /* send ourselves a STOP signal */
+ # ifdef _REENTRANT
+     /* When we didn't suspend immediately in the kill(), do it now.  Happens
+      * on multi-threaded Solaris. */
+     if (!sigcont_received)
+       pause();
+ # endif

 # ifdef WANT_TITLE
     /*
***************
*** 628,633 ****
--- 659,667 ----
 #ifdef SIGTSTP
     signal(SIGTSTP, restricted ? SIG_IGN : SIG_DFL);
 #endif
+ #ifdef _REENTRANT
+     signal(SIGCONT, sigcont_handler);
+ #endif

     /*
      * We want to ignore breaking of PIPEs.
***************
*** 668,673 ****
--- 702,711 ----
 reset_signals()
 {
     catch_signals(SIG_DFL, SIG_DFL);
+ #ifdef _REENTRANT
+     /* SIGCONT isn't in the list, because its default action is ignore */
+     signal(SIGCONT, SIG_DFL);
+ #endif
 }

     static void
*** ../vim-5.5a.7/src/version.c Thu Sep  2 12:43:14 1999
--- src/version.c       Thu Sep  2 12:40:32 1999
***************
*** 420,420 ****
--- 420,421 ----
 {   /* Add new patch number below this line */
+     8,

--
ARTHUR:        A scratch?  Your arm's off!
BLACK KNIGHT:  No, it isn't.
ARTHUR:        Well, what's that then?
BLACK KNIGHT:  I've had worse.
                                 The Quest for the Holy Grail (Monty Python)

--/-/---- Bram Moolenaar ---- [email protected] ---- [email protected] ---\-\--
 \ \    www.vim.org/iccf      www.moolenaar.net       www.vim.org    / /