libthr and 1:1 threading.
Igor Sysoev
is at rambler-co.ru
Thu Apr 3 07:17:28 PST 2003
On Thu, 3 Apr 2003, Terry Lambert wrote:
> > > O_NONBLOCK.
> > >
> > > Examining the Solaris 8 sources, it seems to have been removed from
> > > the disk I/O modules, and applies only to socktpi.c, ptm.c, audio_mc.c,
> > > ecpp.c, and envctrl.c. Apparently, it's also missing from the tty
> > > code, which goes against what Matt claimed, actually.
> >
> > If Solaris 8's stdin handled by tty code then tty supports O_NONBLOCK:
>
> [ ... test program ... ]
>
> Now try redirecting input from a file. O_NONBLOCK is a flag; the
> system doesn't care if you are setting it on a file, a tty, the
> parallel port, or the PTY master; it's just a flag.
And what do you suppose to see in this case ?
----------
>cat t1.c
#include <unistd.h>
#include <errno.h>
#include <fcntl.h>
#include <sys/time.h>
void print_time(char *string, struct timeval *tp0, struct timeval *tp1)
{
long sec, usec;
sec = tp1->tv_sec - tp0->tv_sec;
if ((usec = tp1->tv_usec - tp0->tv_usec) < 0) {
usec += 1000000;
sec--;
}
printf("%s time: %u.%06u\n", string, sec, usec);
}
main()
{
int rc;
char buf[1024];
struct timeval tv0, tv1;
if ((rc = fcntl(0, F_GETFL)) == -1) {
printf("fcntl(F_GETFL) failed: %d: %s\n", errno, strerror(errno));
exit(1);
}
if ((rc = fcntl(0, F_SETFL, rc | O_NONBLOCK)) == -1) {
printf("fcntl(F_SETFL) failed: %d: %s\n", errno, strerror(errno));
exit(1);
}
gettimeofday(&tv0, NULL);
if ((rc = read(0, buf, 1024)) == -1) {
printf("read() failed: %d: %s\n", errno, strerror(errno));
}
gettimeofday(&tv1, NULL);
print_time("read", &tv0, &tv1);
}
>./t1
read() failed: 11: Resource temporarily unavailable
read time: 0.000351
>./t1 < /kernel/genunix
read time: 0.005157
>./t1 < /kernel/genunix
read time: 0.000019
----------
When /kernel/genunix was not cached a read() takes 5157 usec's.
And no EAGAIN error.
> Matt's first argument is that the flag has no effect on disk files
> in FreeBSD; I don't dispute that, and never did.
Not only in FreeBSD. Linux and Solaris do the same.
> His second argument is that if it starts having an effect, there
> is code that people have written that depends on it not having an
> effect, and where they handle every possible error return listed
> on the man page and in the POSIX.1 standard, *except* EAGAIN. And
> this code will break, and that breakage is a violation of POLA.
>
> I happen to disagree with this second argument.
The most Unices ignore O_NONBLOCK for disk files.
So I think programmers never use this flag and select()/etc for disk
files (because it's useless) and I think supporting this flag for disk
files should not break existent software.
But of course it creates portability problems.
> > This Solaris 2.4's readv() man
> > http://www.doc.ic.ac.uk/~mac/manuals/solaris-manual-pages/solaris/usr/man/man2/read.2.html
> > states that O_NONBLOCKed regular disk file can return EAGAIN only
> > if there is a mandatory file/record lock. Solaris 8's man states the same.
>
> Actually, ity does not say "only". It also says:
>
> EAGAIN Total amount of system memory available when
> reading using raw I/O is temporarily insuffi-
> cient.
Yes, but there's no word about EAGAIN while a reading from a disk.
> > > Or the USL SVR4.0.2 or SVR4.2 source code?
> >
> > No, I have not an access to this source code.
> > But if you have an access to these systems it's easy to check whethear
> > these systems supports O_NONBLOCK on disk files or not.
>
> Try redirecting your test program from a file. It's just a flag.
> My Solaris 8 source code and Solaris 8 SPARC box both allow it
> to be set on a file, even if it has no effect.
See above.
Igor Sysoev
http://sysoev.ru/en/
More information about the freebsd-arch
mailing list