Mach trap#-89
svc · mach trap -89
mach_wait_until
Sleep the current thread until an absolute mach_absolute_time() deadline.
Prototype
kern_return_t mach_wait_until(/* 2 args */);Returns: kern_return_t
Version history
| XNU tag | macOS | # |
|---|---|---|
| xnu-123.5 | macOS 10.0 Cheetah | -89 |
| xnu-201 | macOS 10.1 Puma | -89 |
| xnu-344 | macOS 10.2 Jaguar | -89 |
| xnu-517 | macOS 10.3 Panther | -89 |
| xnu-124.1 | — | -89 |
| xnu-124.13 | — | -89 |
| xnu-124.7 | — | -89 |
| xnu-201.14 | — | -89 |
| xnu-201.19 | — | -89 |
| xnu-201.19.3 | — | -89 |
| xnu-201.42.3 | — | -89 |
| xnu-201.5 | — | -89 |
| xnu-344.12.2 | — | -89 |
| xnu-344.2 | — | -89 |
| xnu-344.21.73 | — | -89 |
| xnu-344.21.74 | — | -89 |
| xnu-344.23 | — | -89 |
| xnu-344.26 | — | -89 |
| xnu-344.32 | — | -89 |
| xnu-344.34 | — | -89 |
| xnu-344.49 | — | -89 |
| xnu-517.11.1 | — | -89 |
| xnu-517.12.7 | — | -89 |
| xnu-517.3.15 | — | -89 |
| xnu-517.3.7 | — | -89 |
| xnu-517.7.21 | — | -89 |
| xnu-517.7.7 | — | -89 |
| xnu-517.9.4 | — | -89 |
| xnu-517.9.5 | — | -89 |
Examples
Sleep 5 ms with high precision
#include <mach/mach_time.h>
static mach_timebase_info_data_t tb;
if (tb.denom == 0) mach_timebase_info(&tb);
uint64_t now = mach_absolute_time();
uint64_t ns_to_ticks = (5ULL * 1000000ULL) * tb.denom / tb.numer;
mach_wait_until(now + ns_to_ticks);
Notes
mach_wait_until is the canonical high-resolution sleep on Darwin: it takes a uint64_t deadline in mach ticks (convert ns via mach_timebase_info) and returns when that monotonic time is reached. It is implemented as a thin wrapper around mach_wait_until_trap and is what dispatch_after, CADisplayLink, and most media frameworks ultimately call. Unlike nanosleep it is not interrupted by signals delivered to the process unless the wait is explicitly aborted.
Detection
DTrace mach_trap and sched providers; not surfaced in Endpoint Security.
Related APIs
mach_wait_until_trapmach_absolute_timemach_timebase_infoclock_sleep_trapnanosleep