[zeromq-dev] libzapi: @discuss zclock

Steven McCoy steven.mccoy at miru.hk
Fri Apr 8 15:31:28 CEST 2011


@discuss
> This class contains some small surprises. Most amazing, win32 did an API
> better than POSIX. The win32 Sleep() call is not only a neat 1-liner, it
> also sleeps for milliseconds, whereas the POSIX call asks us to think in
> terms of nanoseconds, which is insane.


Pieter,

  I think you've been beguiled by the Windows API, unsurprisingly in reality
it is pretty terrible.  If you call Sleep() with zero milliseconds you end
up with a yield on older versions of Windows.  Also, you are going to get
only 16ms resolution and you must use timeBeginPeriod() to actually get to
1ms.

On Unix as well as nanosleep() you have access to usleep() for microseconds.

http://pubs.opengroup.org/onlinepubs/007908799/xsh/usleep.html

Moving on,

//  --------------------------------------------------------------------------
//  Return current system clock as milliseconds

int64_t
zclock_time (void)
{
    SYSTEMTIME st;
    GetSystemTime (&st);
    return (int64_t) st.wSecond * 1000 + st.wMilliseconds;
}


This doesn't do what you think it does, use
GetSystemTimeAsFileTime()<http://msdn.microsoft.com/en-us/library/ms724397(v=vs.85).aspx>instead.

I'm surprised you don't have a zclock_delay() API, but I guess depends on
demand.

-- 
Steve-o
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20110408/6fa6cc15/attachment.htm>


More information about the zeromq-dev mailing list