[comp.emacs] Race condition in wait_for_termination.

arndt@zyx.SE (Arndt Jonasson) (06/29/88)

In Gnu Emacs 18.49, under HP-UX (equivalent to SYSV in this context),
there is a race condition in the C function wait_for_termination in
sysdep.c. The code looks like:

wait_for_termination (pid)
int pid;
{
   while (1)
   {
      if (0 > kill (pid, 0))
	 break;
      pause ();
   }
}

Assuming that the process named by 'pid' is running when 'kill' is
called, but exits just after 'kill' returns, the return value from
'kill' will indicate that the process is still running, and thus the
'pause' is entered, where it will wait indefinitely, or until ^G or
some other interrupt occurs.

This is relevant at least for code using the Lisp function
'call-process' to call inferior processes, e.g. M-X dired.

The chance for the race condition to actually occur seems slim, but
for some reason it has a more than 50% probability of occurring in my
present system configuration.

I'm not sure about what the best remedy is; I changed the 'pause' to
'sleep(2)' which makes dired work for me; I'm not sure whether it
doesn't break something else.
-- 
Arndt Jonasson, ZYX Sweden AB, Styrmansgatan 6, 114 54 Stockholm, Sweden
email address:	 arndt@zyx.SE	or	<backbone>!mcvax!enea!zyx!arndt