Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 27 Feb 2001 12:51:11 -0800 (PST)
From:      Marc W <mwlist@lanfear.com>
To:        Peter Dufault <dufault@hda.hda.com>, Marc W <mwlist@lanfear.com>
Cc:        freebsd-hackers@FreeBSD.ORG
Subject:   Re: Where can I find out rules on blocking in threads?
Message-ID:  <200102272051.MAA42206@akira.lanfear.com>

next in thread | raw e-mail | index | archive | help

> 
> I think the FreeBSD behavior is wrong, the spec says that when
> opening a FIFO with O_NONBLOCK clear that:
>
> > An open() for reading-only shall block the calling thread until a
> > thread opens the file for writing.  An open() for writing-only
> > shall block the calling thread until a thread opens the file for
> > reading.
> 
> The FBSD man pages will let you know if something will block or
> not, for example, look at the "implementation notes" section for
> open.

> You can open the fifo non-blocking and then clear O_NONBLOCK using
> fcntl, hopefully that will work in all environments.

    I have tried this, but it gets even weirder then:

    - the call to open always succeeds right away (even when there are
no threads on the write end of the fifo)
    - the immediately following call to read() also succeeds, returning
0 bytes as the number of bytes read.


    it gets worse -- when i change my loop to be:

    while (1) {

            fifo = open(fifoPath, O_RDONLY | O_NONBLOCK);
            cread = read(fifo, buf, sizeof(buf));
            if (cread > 0) do_something();
            close(fifo);
            usleep(100000);
    }

    anybody who tries to open the write end of the fifo ends up hanging
..


    argh!  i'll keep investigating...  my poor "2 hour solution to
single instancing" is going into day 3 :-)

    marc.



To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200102272051.MAA42206>