[Haifux] Implementing read() like UNIX guys like it

Nadav Har'El nyh at math.technion.ac.il
Tue Apr 26 14:51:48 MSD 2011


On Sat, Apr 23, 2011, Eli Billauer wrote about "Re: [Haifux] Implementing read() like UNIX guys like it":
> >if the user calls "read" and there is data - return what you have to the
> >user without blocking.
> That is one of the options I considered. The drawback of doing this 
> exactly like this, is that if data arrives at a slow rate (say, 100 
> kB/sec) it's likely that every read() operation will yield one byte of 
> data, making the CPU spin around this instead of doing something useful.

Two things make this a non-issue (or at least a not-very-important issue).

First, if the data arrives at a slow rate, it doesn't really matter how
optimized your code is - nobody will notice the difference anyway.

Second, if the CPU *did* have "something useful" to do (run other processes,
or whatever), it would, causing a bit more time to pass between the read()
and it might return more than one byte. It will only return one byte when
there's nothing better to do than calling read() all the time.

-- 
Nadav Har'El                        |      Tuesday, Apr 26 2011, 22 Nisan 5771
nyh at math.technion.ac.il             |-----------------------------------------
Phone +972-523-790466, ICQ 13349191 |Open your arms to change, but don't let
http://nadav.harel.org.il           |go of your values.



More information about the Haifux mailing list