[599] in Pthreads mailing list archive

home help back first fref pref prev next nref lref last post

blocking read with close

daemon@ATHENA.MIT.EDU (John H. Aughey)
Fri Mar 14 17:11:30 1997

To: pthreads@MIT.EDU
Date: Fri, 14 Mar 1997 13:57:17 -0800
From: "John H. Aughey" <jha@freefall.freebsd.org>

I am implementing a multi threaded network program where multiple
threads threads read from their own network connections and feed
into queues, etc.  There are situations when I want to terminate
a network connection.  I've done this with other thread implementations
by closing the descriptor which will cause read to return with an
error.

I understand if one thread closes a descriptor that another thread
is blocked on reading the behavior is undefined.  In this case, it
causes the closing thread to block so both threads are blocked.
Someone suggested a work around by createing a socketpair or pipe
and select on both the fd and the pipe and to indicate the file
should be closed you write to the pipe.  However this work around
is costly becuase of the extra checking that needs to be done.

Is there a better solution?

-John

home help back first fref pref prev next nref lref last post