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 Win32Sleep()call defaults to 16ms resolution unless the system timer resolution is increased with a call totimeBeginPeriod()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 ๐
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 ๐
zeromq-dev@lists.zeromq.orgmailto: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
- fedora 44: czmq-devel 4.2.1-24.fc44 ยท MPL-2.0
- fedora 44: czmq-devel 4.2.1-24.fc44 ยท MPL-2.0
- ubuntu resolute: libczmq-dev 4.2.1-3build1 ยท MPL-2.0
- ubuntu stonking: libczmq-dev 4.2.1-3build1 ยท MPL-2.0
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms