Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 15 Feb 2002 11:26:36 -0600
From:      mikea <mikea@mikea.ath.cx>
To:        questions@FreeBSD.ORG
Subject:   Re: a multhreaded application hanging
Message-ID:  <20020215112636.C44334@mikea.ath.cx>
In-Reply-To: <200202151711.g1FHB6X78810@aldan.algebra.com>; from mi@aldan.algebra.com on Fri, Feb 15, 2002 at 12:11:03PM -0500
References:  <200202151711.g1FHB6X78810@aldan.algebra.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020215112636.C44334>