Re: [off topic] A pause in C?
-----Original Message-----
From: mickyb@es.co.nz <mickyb@es.co.nz>
To: debian-user@lists.debian.org <debian-user@lists.debian.org>
Date: 07 October 1998 01:42
Subject: [off topic] A pause in C?
>
>I am after a way to generate a pause of 300ns in a C program I am working
>on. 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)
>I was looking at the info page for libc (which seems to be broken.. I cant
>go to other nodes from 'info libc') and found the timeval structure. It
>looks like what I want, but I cant work it out.. can someone help?
>
>something like:
>
>void p_300ns()
>{
> struct timeval interval;
>
> // assign interval its members here.. ??
>
> long int start = interval->tv_usec;
>
> do {
> // assign interval its members here again
> } while interval->tv_usec < start + 3<some zero's>;
>
> // have to excuse my memory.. ^^^^^^^^^^^^^^^ what is nano ? micro
> // is one millionth, nano is one something thousandth.. ??
>
Try using sleep() or nsleep() (I am not sure its name is nsleep() or
something similar), or if they don't work another approach would be a loop
with a call to clock() at the beginning and antoher one while checking at
the end of the loop.
Reply to: