Re: [off topic] A pause in C?
On 7 Oct 1998, Miquel van Smoorenburg wrote:
> In article <[🔎] Pine.LNX.3.96.981007123258.2069A-100000@omnic.rumpus.net>,
> Michael Beattie <mickyb@es.co.nz> wrote:
> >I am after a way to generate a pause of 300ns in a C program I am working
> >on.
>
> In general, you cannot guarantee pauses in a multitasking system
> like Unix or Linux. Pauses can be set in microseconds using usleep(),
> but not in nanoseconds. And even then that is only the _minimum_ time
> that call will sleep - if the system decides to run another process
> at that point your program will only continue until the timeslice
> of the other process is over, 10 ms later ..
A greater pause would not matter, but in the interests of not making a
user wait for ever... The pause needs to be greater than 200ns. Mike Stone
replied with 'man nanosleep' which is what I am after.. then again, a 10ms
wait would probably do..
> >At the moment, I am using a for loop of about 700000 iterations..
> >works okay, but on a faster system it will die.. (needed to slow down I/O
> >with an interface card)
>
> If you need to do timing that strict, and you're talking to hardware,
> you shouldn't do it from userspace but write a kernel module instead.
But of an overkill... the timing does not need to be strict.. but like I
said above, just a minimum pause of 200ns.
Thanks anyway, but I dont quite feel up to writing a module.. yet.
The programs that came with the interface card are for QBASIC, and the
amount of time it took the interpreter to execute the port I/O, there was
no need for a pause.. but C is incredibly fast *G*, and thus I need a
small pausing routine.
> Or you could use Linux-RT (Real Time), but the real time programs you
> have to create for Linux-RT are essentially kernel modules too ..
Nope.. normal C is good enough for me :)
Thanks for the reply, nanosleep() or usleep() will do the trick.
Michael Beattie (mickyb@es.co.nz)
PGP Key available, reply with "pgpkey" as subject.
-----------------------------------------------------------------------------
Def: Password: The nonsense word taped to the CRT.
-----------------------------------------------------------------------------
Debian GNU/Linux.... Ooohh You are missing out!
Reply to: