[JDEV] FreeBSD and MIO

Craig ckaes at jabber.com
Fri Dec 8 12:15:23 CST 2000


Howdy, Keith.

In our pthreads efforts, we've tried to get away from signals because signals and
threads don't mix too well.  Instead of signalling the mio_main thread when we want
to interrupt the select call,  here's what we do:

1) Create a bidirectional pipe on init.
2) Add the read end of it to the select all_rfds (each pass through the loop).
3)  When we want to interrupt the select, we write a byte to the write end.
4)  When the select call wakes up, it clears the pipe and carries on.

Voila, signal-less interrupt of select.  Credit Dan Berstein.

--C

Keith Minkler wrote:

> Jdev,
>
> I finnaly found the FreeBSD select(2) bug.. (well, my bug, not FreeBSD's) *G*
>
> It has to do with differences in how linux and FreeBSD handle select(2) getting
> interupted by a signal.  On Linux, it clears the FD sets you pass into it, but
> on FreeBSD, it leaves the sets untouched.  (Thank GOD for man pages).  It is
> easily fixed by checking the return value of select(2), and not trying to read(2),
> write(2), or accept(2) from the sockets on an error condition (-1) such as
> when the loop is signalled.
>
> *phew*  with much joy, FreeBSD will be able to share in the 1.4 bliss, along with
> the rest of the community.. *G*
>
> Keith Minkler
>
> _______________________________________________
> jdev mailing list
> jdev at jabber.org
> http://mailman.jabber.org/listinfo/jdev





More information about the JDev mailing list