X-Spam-Check-By: sourceware.org Message-ID: <449B49A2.7E5EB78B@dessent.net> Date: Thu, 22 Jun 2006 18:53:38 -0700 From: Brian Dessent X-Mailer: Mozilla 4.79 [en] (Windows NT 5.0; U) MIME-Version: 1.0 To: cygwin AT cygwin DOT com Subject: Re: CygPerl hangs opening FIFO after fork (in both parent&child) References: <449B08E2 DOT 9040302 AT tlinx DOT org> Content-Type: multipart/mixed; boundary="------------A562CCCFB3E2460512A6411A" X-IsSubscribed: yes Reply-To: cygwin AT cygwin DOT com Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com --------------A562CCCFB3E2460512A6411A Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Linda Walsh wrote: > The attached test case is simple and fairly short. It does not > depend on File::BOM (and has none of the code from it). > > It's only dependency (other than perl) is the POSIX module, > where, from, the "fifo" command is taken. This appears to be a deadlock in the Cygwin DLL when both the reader and writer end of a fifo tries to open the file at the same time (or nearly the same time.) They end up signaling each other to ask about the other end of the pipe, and hang there. It has nothing to do with perl or fork, as far as I can tell -- the attached C testcase will work fine if the reader end sleeps briefly to ensure the opening order. It's just a classic race condition somewhere. Brian --------------A562CCCFB3E2460512A6411A Content-Type: text/plain; charset=us-ascii; name="fifo_testcase_simpler.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="fifo_testcase_simpler.c" #include #include #include #include #include #include #include #define FIFO_FILENAME "test_fifo" #define ERROR_EXIT(x) { perror(x); exit (EXIT_FAILURE); } int main (int argc, char **argv) { int fd; pid_t pid; unlink (FIFO_FILENAME); if (mkfifo (FIFO_FILENAME, 0700) == -1) ERROR_EXIT ("mkfifo"); if ((pid = fork ()) > 0) { printf ("parent: I am %d, child is %d\n", getpid (), pid); if (argc > 1) { puts ("parent: sleeping"); sleep (1); } puts ("parent: opening fifo"); if ((fd = open (FIFO_FILENAME, O_RDONLY)) == -1) ERROR_EXIT ("parent open"); puts ("parent: closing fifo"); close (fd); puts ("parent: waiting for child"); if (waitpid (pid, NULL, 0) != pid) ERROR_EXIT ("parent waitpid"); puts ("parent: removing fifo"); if (unlink (FIFO_FILENAME) != 0) ERROR_EXIT ("parent unlink"); puts ("parent: exiting"); exit (EXIT_SUCCESS); } else if (pid == 0) { puts ("child: opening fifo"); if ((fd = open (FIFO_FILENAME, O_WRONLY)) == -1) ERROR_EXIT ("child open"); puts ("child: closing fifo"); close (fd); puts ("child: exiting"); exit (EXIT_SUCCESS); } else ERROR_EXIT ("fork"); } --------------A562CCCFB3E2460512A6411A Content-Type: text/plain; charset=us-ascii -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/ --------------A562CCCFB3E2460512A6411A--