From owner-freebsd-questions Fri Feb 15 9:26:40 2002 Delivered-To: freebsd-questions@freebsd.org Received: from mikea.ath.cx (okc-65-30-192-11.mmcable.com [65.30.192.11]) by hub.freebsd.org (Postfix) with ESMTP id C29D737B400 for ; Fri, 15 Feb 2002 09:26:37 -0800 (PST) Received: (from mikea@localhost) by mikea.ath.cx (8.11.6/8.11.1) id g1FHQa844430 for questions@FreeBSD.ORG; Fri, 15 Feb 2002 11:26:36 -0600 (CST) (envelope-from mikea) Date: Fri, 15 Feb 2002 11:26:36 -0600 From: mikea To: questions@FreeBSD.ORG Subject: Re: a multhreaded application hanging Message-ID: <20020215112636.C44334@mikea.ath.cx> References: <200202151711.g1FHB6X78810@aldan.algebra.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <200202151711.g1FHB6X78810@aldan.algebra.com>; from mi@aldan.algebra.com on Fri, Feb 15, 2002 at 12:11:03PM -0500 Sender: owner-freebsd-questions@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG On Fri, Feb 15, 2002 at 12:11:03PM -0500, Mikhail Teterin wrote: > Hi! > > I'm trying to port a multithreaded C++ application (using the sendmail's > milter library). > > It seems to work most of the time, but every once in a while hangs in > the following line: > > size=read(pipe_io[1][0],iobuff,1024); > > I tried to ktrace it when it gets into this state, and ktrace.out > remains empty. The process is in the ``piperd'' state, as reported > by ps. Why would read(2) be hanging? > > The OS is 4.5-STABLE and I already recompiled the libc_r with the > not-yet-MFCed patches to uthread_attr_setscope.c and uthread_dup2.c > but that did not change a thing... What if the process at the other end of the pipe hasn't put anything in the pipe and is blocked? Or am I missing something somewhere? Timing problems like this are very common when developing apps that have intercommunicating processes. Maybe you could have the reader process check a semaphore or something to see if the writer process has filled the pipe, and sleep or do something else if the pipe-is-ready signal is up? Or is there a way to test a pipe for readability without actually doing the read? ISTR something about that, but I haven't written a program using pipes in a long time, and that info is paged out. I'm sure one of the older and wiser heads will have a better answer, but this is the sort of approach I've used when writing MVS system code for our dinosaur. -- Mike Andrews mikea@mikea.ath.cx Tired old sysadmin since 1964 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-questions" in the body of the message