From 37d5841f83200da2d481d6b01c111a37acf8ca39 Mon Sep 17 00:00:00 2001 From: Christopher Faylor Date: Mon, 17 Jan 2005 04:12:08 +0000 Subject: * pinfo.h (maybe_set_exit_code_from_windows): Renamed from set_exit_state. * pinfo.cc (pinfo::exit): Use renamed function. (proc_waiter): Ditto. Make a copy of input argument to avoid problems when procs array is shuffled. Flag when copy is made so that remove_proc knows when it is safe to reshuffle. * sigproc.cc (proc_terminate): Don't flag process_state as PID_EXITED. (remove_proc): Wait for waiter to finish copying pinfo element before moving it (an actual wait should be an extremely rare event). --- winsup/cygwin/sigproc.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'winsup/cygwin/sigproc.cc') diff --git a/winsup/cygwin/sigproc.cc b/winsup/cygwin/sigproc.cc index fb0680867..b99a90c87 100644 --- a/winsup/cygwin/sigproc.cc +++ b/winsup/cygwin/sigproc.cc @@ -65,8 +65,9 @@ Static HANDLE wait_sig_inited; // Control synchronization of // message queue startup Static int nprocs; // Number of deceased children -Static char cprocs[(NPROCS + 1) * sizeof (pinfo)]; // All my deceased children info -#define procs ((pinfo *) cprocs) +Static char cprocs[(NPROCS + 1) * sizeof (pinfo)];// All my children info +#define procs ((pinfo *) cprocs) // All this just to avoid expensive + // constructor operation at DLL startup Static waitq waitq_head = {0, 0, 0, 0, 0, 0, 0};// Start of queue for wait'ing threads muto NO_COPY *sync_proc_subproc = NULL; // Control access to subproc stuff @@ -406,8 +407,6 @@ proc_terminate (void) for (i = 0; i < nprocs; i++) { procs[i]->ppid = 1; - if (!proc_exists (procs[i])) - procs[i]->process_state = PID_EXITED; /* CGF FIXME - still needed? */ if (procs[i].wait_thread) { // CloseHandle (procs[i].rd_proc_pipe); @@ -860,7 +859,15 @@ remove_proc (int ci) ForceCloseHandle1 (procs[ci].hProcess, childhProc); } if (ci < --nprocs) - procs[ci] = procs[nprocs]; + { + /* Wait for proc_waiter thread to make a copy of this element before + moving it or it may become confused. The chances are very high that + the proc_waiter thread has already done this by the time we + get here. */ + while (!procs[nprocs].waiter_ready) + low_priority_sleep (0); + procs[ci] = procs[nprocs]; + } return 0; } -- cgit v1.2.3