[616] in Pthreads mailing list archive
Re: blocking read with close
daemon@ATHENA.MIT.EDU (Vance Huntley)
Fri Mar 21 19:48:56 1997
In-Reply-To: <199703142157.NAA14309@freefall.freebsd.org>
Date: Fri, 21 Mar 1997 19:27:20 -0500
To: "John H. Aughey" <jha@freefall.freebsd.org>
From: Vance Huntley <vance@webgenesis.com>
Cc: pthreads@MIT.EDU
At 16:57 -0500 3/14/97, John H. Aughey wrote:
>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
How about sending a SIGINT? This will cause read() to return with errno
set to EINTR, which you can then trap for and handle appropriately.
Depending on your threads implementation, you may not be able to send the
signal to the specific thread you are interested in, but you can always
restart the reads in the threads which don't need to stop yet.
Vance
------------
Vance Huntley
Director of Technology (& Chat Guy)
WebGenesis, Inc., Ithaca, NY 14850
vance@webgenesis.com --- 607.255.8499
Check out "The Globe"! --- http://www.theglobe.com/
------------