top/contents search
[This answer was contributed by Pedro Zorzenon Neto.]

The functions usleep and nanosleep do not work for small intervals, since the kernel [can] change to another task...

The solution comes out from I/O instructions. Writing to I/O ports in ISA addresses will cause the system to wait for 1 microsecond since the ISA bus access time is 1 microsecond. One I/O port that is never used by the hardware in i386 machines is port 0x80.

So, writing one byte to I/O port 0x80 will result in a ``one microsecond delay''. This is not so accurate, but at least it will vary less than 2% (my tests) from a Pentium 100 and a Athlon 850.

Some GNU/Linux low-level drivers also use this ``feature'' of writting to port 0x80.

Attached is the program [and the header file] that I used to do this (you can adapt it to MS-DOS, I think the functions are inportb and outportb, but not sure).

In GNU/Linux you will need root permissions to write to I/O ports.


contents search
about this FAQ list   about eskimo   search   feedback   copyright

Hosted by Eskimo North