ZCLOCK(3)

โœจ zclock โ€” the millisecond clock & delay bestie โœจ

okay so this is zclock(3) from the CZMQ Manual, and bestie it's literally just clocks and naps. millisecond clocks. millisecond delays. that's the whole vibe. ๐Ÿ’…


๐ŸŒธ NAME ๐ŸŒธ

zclock โ€” class for millisecond clocks and delays. yes that's it. it does time and it does sleep. iconic behavior honestly. โฐ๐Ÿ’ค


๐ŸŽ€ SYNOPSIS ๐ŸŽ€

k so heads up before we get into it: this is a stable class, and it may not change except for emergencies. so like, don't expect drama. it's giving stability. ๐Ÿซถ

//  This is a stable class, and may not change except for emergencies. It
//  is provided in stable builds.
//  Sleep for a number of milliseconds
CZMQ_EXPORT void
    zclock_sleep (int msecs);

//  Return current system clock as milliseconds. Note that this clock can
//  jump backwards (if the system clock is changed) so is unsafe to use for
//  timers and time offsets. Use zclock_mono for that instead.
CZMQ_EXPORT int64_t
    zclock_time (void);

//  Return current monotonic clock in milliseconds. Use this when you compute
//  time offsets. The monotonic clock is not affected by system changes and
//  so will never be reset backwards, unlike a system clock.
CZMQ_EXPORT int64_t
    zclock_mono (void);

//  Return current monotonic clock in microseconds. Use this when you compute
//  time offsets. The monotonic clock is not affected by system changes and
//  so will never be reset backwards, unlike a system clock.
CZMQ_EXPORT int64_t
    zclock_usecs (void);

//  Return formatted date/time as fresh string. Free using zstr_free().
//  Caller owns return value and must destroy it when done.
CZMQ_EXPORT char *
    zclock_timestr (void);

//  Self test of this class.
CZMQ_EXPORT void
    zclock_test (bool verbose);

Please add '@interface' section in './../src/zclock.c'.


๐Ÿ’– DESCRIPTION ๐Ÿ’–

so the zclock class is the one handing out the essential sleep and system time functions. it's the one you call when you wanna slow down threads for testing (yes, thread naps, we love a rest era) or calculate timers for polling.

the whole point? it wraps the non-portable system calls in a simple portable API. so you write it once, it works everywhere, no "but what about Windows" meltdown. main character energy fr fr. ๐Ÿ‘‘

โš ๏ธ important tea: the Win32 Sleep() call defaults to 16ms resolution unless the system timer resolution is increased with a call to timeBeginPeriod() permitting 1ms granularity. so like, if your sleeps are looking kinda chunky on Windows, that's why. no cap.

๐ŸŒˆ EXAMPLE ๐ŸŒˆ

straight from the zclock_test method, verbatim, because I would never:

int64_t start = zclock_time ();
zclock_sleep (10);
assert ((zclock_time () - start) >= 10);
start = zclock_mono ();
int64_t usecs = zclock_usecs ();
zclock_sleep (10);
assert ((zclock_mono () - start) >= 10);
assert ((zclock_usecs () - usecs) >= 10000);
char *timestr = zclock_timestr ();
if (verbose)
    puts (timestr);
freen (timestr);

#if defined (__WINDOWS__)
zsys_shutdown();
#endif

see how it grabs zclock_time() before and after a zclock_sleep (10) and asserts the difference is >= 10? that's the vibe check passing. โœจ and then it does the same lil dance with zclock_mono() and zclock_usecs(), except the usecs assert wants >= 10000 because microseconds, bestie. math. ๐Ÿงฎ๐Ÿ’…

also note the freen (timestr) โ€” you gotta free that zclock_timestr () string. it's yours. caller owns it. clean up after yourself. ๐Ÿงน


๐Ÿฆ‹ AUTHORS ๐Ÿฆ‹

the czmq manual was written by the authors in the AUTHORS file. mysterious. iconic. we don't know their names but we thank them. ๐Ÿ™


๐Ÿ’œ RESOURCES ๐Ÿ’œ

  • Main web site:
  • Report bugs to the email <zeromq-dev@lists.zeromq.org[1]>

Copyright (c) the Contributors as noted in the AUTHORS file. This file is part of CZMQ, the high-level C binding for 0MQ: http://czmq.zeromq.org. This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/. LICENSE included with the czmq distribution.

like fr, read the license. it's legally binding and also slay.

๐Ÿ“ NOTES ๐Ÿ“

  1. zeromq-dev@lists.zeromq.org mailto:zeromq-dev@lists.zeromq.org

and that's the whole page, bestie!! CZMQ 4.2.1, dated 01/16/2026, straight from the ZCLOCK(3) corner of the CZMQ manual. go forth and sleep (in milliseconds) responsibly. ๐Ÿซถ๐Ÿ’–โœจ

๐Ÿ“ฆ where this page comes from