[MPlayer-dev-eng] Re: kernel: to do_select(pipe) or not to do
Ivan Kalvachev
ivan at cacad.com
Mon Nov 22 23:15:32 CET 2004
Richar, your post is good, but I am not sure Linus reads this maillist.
Forward it to him too. This is valid and for the others.
On Mon, 22 Nov 2004, D Richard Felker III wrote:
> On Sun, Nov 21, 2004 at 08:21:58PM -0800, Linus Torvalds wrote:
>
> hi linus.
>
[..]
> I hope you are only referring to non-blocking I/O above. For
> blocking I/O, the write request must be fully satisfied before
> returning, otherwise the caller blocks. When you call select(),
> the kernel has no idea how much you want to write. If there's
> room for a byte to be written, but no more, select() can
> return with the fd ready for writing.
>
> Please see:
>
> http://www.opengroup.org/onlinepubs/009695399/functions/write.html
I already gave that point. But in this case select() should block even
on empty pipe because write PIPE_BUF+1 write will block.
There is no more sense on making select() block on half full buffer
than always block or block after first write.
On Mon, 22 Nov 2004 18:26:16 +0100
G_bor L_n_rt <lgb at lgb.hu> wrote:
> On Mon, Nov 22, 2004 at 10:35:52AM -0500, D Richard Felker III wrote:
> > > As I already mentioned, "select()" usage ONLY MAKES SENSE FOR NONBLOCKING
> > > FILE DESCRIPTORS.
> > >
> > > Of _course_ a write() will block if the fd is blocking. But if you have a
> > > nonblocking fd it will NOT block.
> >
> > a write should never block if select indicated that the fd was
> > writeable. it should write however many bytes can be written
>
> Maybe I'm wrong at this point but what about if you got "fd is
> writeable" from select but before reaching write() another
> thread got control and writes something? I mean: use select() _THEN_
> write() is not an atomic operation of course so race condition
> can be experienced here. I'm assuming this because of Linux
> specific clone() system call (CLONE_FILES flag) which is/can be
> used to create threads.
>
> But this whole blocking/non-blocking issue from the point of
> view of the kernel is quite unknown for me, so maybe I'm wrong.
This race condition is documented. If i am not wrong pselect() is
the workaround but linux doesn't implement it (have to check).
Wish You Best
Ivan Kalvachev
iive
More information about the MPlayer-dev-eng
mailing list