[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: gettimeofday() and clock



Francesco Orsenigo wrote:

>>Eh?  usec is short for MICROSECOND (a millionth of a second).
> 
> Ooops... for somewhat reasons i belived they were 1000... (what a shame...)

That would be a MILLISECOND - abbreviated ms.

>>Use gettimeofday - it's working just fine - you must have some other problem.
> 
> In fact i confused the sleep() error (about 10000 usecs) with the effective 
> MILLIsecs passed, without wrap (it was very strange...)

Yes - both 'sleep' and 'usleep' sleep for wildly inaccurate amounts of time.

usleep is given an argument in MICROSECONDS - but in practice it can't wake
your program up any faster than the kernel timeslice - which is 1/50th second.

Hence, a usleep of much less than 20,000 microseconds could still sleep for
over 20,000us.

Whilst you have a pretty accurate timer in gettimeofday, there isn't a way
to give up CPU time for an accurate amount of time.  This can be a major
pain when you're writing serious realtime stuff.

> Ok, i'll promise i'll never make such posts again...

We all make stoopid mistakes from time to time - don't sweat it.

----------------------------- Steve Baker -------------------------------
Mail : <sjbaker1@airmail.net>   WorkMail: <sjbaker@link.com>
URLs : http://www.sjbaker.org
        http://plib.sf.net http://tuxaqfh.sf.net http://tuxkart.sf.net
        http://prettypoly.sf.net http://freeglut.sf.net
        http://toobular.sf.net   http://lodestone.sf.net