Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 Jan 2005 15:13:58 -0000
From:      "Niall Douglas" <s_sourceforge@nedprod.com>
To:        freebsd-threads@freebsd.org
Subject:   Re: Trying again: select() should be a cancellation point
Message-ID:  <41FBA836.25106.48EDC638@localhost>
In-Reply-To: <41FB9E30.1726.48C69D9F@localhost>

next in thread | previous in thread | raw e-mail | index | archive | help
On 29 Jan 2005 at 14:31, Niall Douglas wrote:

> As no one replied last time, here's this email again.
> 
> I've found that I cannot work around select() not being a 
> cancellation point on FreeBSD in my code - I had to #ifdef 
> __FreeBSD__ in a hack which manually calls pthread_testcancel() every
> second. This is *nasty*!
> 
> If there's any alternative, I'd very much like to hear it. Preferably
> I'd like to see select() made a cancellation point or a new form of
> select() eg; select_tc() added.

Isn't it typical that five minutes after you send an email you 
realise you were wrong? :(

It seems that select() indeed IS a cancellation point. What was 
happening was that my code does the following:

1. Thread waits on non-blocking read pipe using select()
2. Thread gets cancelled. This invokes thread cancellation handler.
3. Thread cancellation handler sends a "I am disconnecting" message 
to write pipe. Note that this is a blocking pipe not the same as the 
read pipe. The message is tiny, around 20 bytes.

Now on all systems, the write pipe is always kept fully empty and 
because they have a 4Kb buffer, 20 bytes should NEVER stall. But on 
FreeBSD it does stall where it does not on Linux nor WinNT. And 
that's why I had thought select() was not a cancellation point as the 
thread seemed to never die.

Note that sockets work fine here, as do files ie; you CAN write data 
to these during a thread cancellation handler. Unfortunately it seems 
the same is not true for pipes.

So what's going on then? Thoughts? You guys will probably want a 
short example ...

Cheers,
Niall

> > According to:
> > 
> > http://lists.freebsd.org/pipermail/freebsd-threads/2004-
> > October/002572.html
> > 
> > ... it is. But v5.3 FreeBSD doesn't cancel during select(), nor
> > during recv().
> > 
> > OTOH I have other documentation which suggests that neither select()
> > nor recv() are cancellation points.
> > 
> > Oh and on Linux, both are cancellation points. In my mind it's
> > probably more useful if they are cancellation points as you can
> > always disable cancellation around them if necessary whereas the
> > opposite is not true.
> > 
> > Cheers,
> > Niall
> > 
> 
> 
> 
> _______________________________________________
> freebsd-threads@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-threads
> To unsubscribe, send any mail to
> "freebsd-threads-unsubscribe@freebsd.org"
> 
> 






Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?41FBA836.25106.48EDC638>