[617] in Pthreads mailing list archive

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

Re: blocking read with close

daemon@ATHENA.MIT.EDU (Michael Widenius)
Sat Mar 22 06:16:39 1997

Date: Sat, 22 Mar 1997 13:10:16 +0200 (EET)
From: Michael Widenius <monty@tcx.se>
To: Vance Huntley <vance@webgenesis.com>, pthreads@MIT.EDU,
        jha@freefall.freebsd.org
In-Reply-To: <v0300780baf58d69b5ebf@[205.232.65.100]>
Reply-To: monty@analytikerna.se


>>>>> "Vance" == Vance Huntley <vance@webgenesis.com> writes:

Vance> 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

Vance> How about sending a SIGINT?  This will cause read() to return with errno
Vance> set to EINTR, which you can then trap for and handle appropriately.
Vance> Depending on your threads implementation, you may not be able to send the
Vance> signal to the specific thread you are interested in, but you can always
Vance> restart the reads in the threads which don't need to stop yet.

Vance> Vance

The current version of MIT threads doesn't support sending signal to
break reads (or select).

I have fixed this in the MIT threads distribution that comes with
mysql. Get it at http::/www.tcx.se/

You have to get the file mysql-3.20.13-beta.tar.gz.

In this distribution you also have a file 'mysys/thr_alarm.c' with
shows how to handle read with alarms.

Monty

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