How to sleep accurately
Bill Baxter
dnewsgroup at billbaxter.com
Wed Jun 27 22:38:37 PDT 2007
Jason House wrote:
> Daniel Giddings wrote:
>> I'm not sure of the best way to do it but I'm interested in what
>> people think ;-)
>>
>> You can use gettimeofday under linux instead of clock. It's in
>> std.c.linux.linux.
>>
>> long getTime() // in ms
>> {
>> timeval t;
>> struct_timezone z;
>>
>> gettimeofday(&t, &z);
>>
>> return t.tv_sec * 1000 + t.tv_usec / 1000;
>> }
>
> Thanks. I'm using that and it seems to be working well... I'll have to
> add some kind of check for the end of the day.
"""
The gettimeofday() function shall obtain the current time, expressed as
seconds and microseconds since the Epoch, and store it in the timeval
structure pointed to by tp. The resolution of the system clock is
unspecified.
"""
So no, you don't have to worry about the end of the day, just the end of
something like 2^32 or 2^64 seconds from around January 1970, depending
on your platform.
--bb
More information about the Digitalmars-d-learn
mailing list