#include <mach/semaphore.h> also included by <mach/mach.h>

mach/semaphore.h

Forward Declarations The semaphore creation and deallocation routines are defined with the Mach task APIs in <mach/task.h>. kern_return_t semaphore_create(task_t task, semaphore_t *new_semaphore, sync_policy_t policy, int value); kern_return_t semaphore_destroy(task_t task, semaphore_t semaphore);
7 functions

functionsemaphore_signal

extern kern_return_t semaphore_signal(semaphore_t semaphore)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Increments the semaphore count.
The semaphore_signal function increments the semaphore count. If the count goes non-negative (i.e. greater than or equal to 0) and a thread is blocked on the semaphore, then the waiting thread is scheduled to execute. If multiple threads are blocked on the semaphore, the thread scheduled to execute is selected according to the wakeup policy of the semaphore (set when the semaphore was created via semaphore_create). Device driver interrupt service routines may safely execute semaphore_signal operations without causing a deadlock.
KERN_INVALID_ARGUMENTThe specified semaphore is invalid.
KERN_TERMINATEDThe specified semaphore has been destroyed.
KERN_SUCCESSThe semaphore has been signalled.

functionsemaphore_signal_all

extern kern_return_t semaphore_signal_all(semaphore_t semaphore)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Wake up all threads blocked on a semaphore.
The semaphore_signal_all function wakes up all of the threads blocked on the semaphore. The semaphore count is reset to zero.
KERN_INVALID_ARGUMENTThe specified semaphore is invalid.
KERN_TERMINATEDThe specified semaphore has been destroyed.
KERN_SUCCESSThe semaphore has been signalled.

functionsemaphore_wait

extern kern_return_t semaphore_wait(semaphore_t semaphore)
CMU/MIT Mach reference · manual page · © Carnegie Mellon
Wait on the specified semaphore.
The semaphore_wait function decrements the semaphore count. If the semaphore count is negative after decrementing, the calling thread blocks. Device driver interrupt service routines (ISR) should never execute semaphore_wait, since waiting on a semaphore at the ISR level may, and often will, lead to a deadlock.
KERN_INVALID_ARGUMENTThe specified semaphore is invalid.
KERN_TERMINATEDThe specified semaphore has been destroyed.
KERN_ABORTEDThe caller was blocked due to a negative count on the semaphore, and was awoken for a reason not related to the semaphore subsystem (e.g. thread_terminate).
KERN_SUCCESSThe semaphore wait operation was successful.

functionsemaphore_timedwait

extern kern_return_t semaphore_timedwait(semaphore_t semaphore, mach_timespec_t wait_time)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/sync_sema.c
Like semaphore_wait, but blocks for at most wait_time. A wait_time of {0,0} is non-blocking: if the semaphore is unavailable, KERN_OPERATION_TIMED_OUT is returned immediately. Returns KERN_SUCCESS when the wait is satisfied, KERN_OPERATION_TIMED_OUT on timeout, KERN_ABORTED if interrupted, KERN_TERMINATED if the semaphore is destroyed while waiting, KERN_INVALID_ARGUMENT for a null semaphore, and KERN_INVALID_VALUE for a malformed mach_timespec_t.

functionsemaphore_timedwait_signal

extern kern_return_t semaphore_timedwait_signal(
	semaphore_t wait_semaphore,
	semaphore_t signal_semaphore,
	mach_timespec_t wait_time
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/sync_sema.c
Atomically registers a wait on wait_semaphore and then signals signal_semaphore, blocking for at most wait_time; equivalent to semaphore_wait_signal with a timeout. A wait_time of {0,0} is non-blocking. Returns KERN_SUCCESS, KERN_OPERATION_TIMED_OUT on timeout, KERN_ABORTED if interrupted, KERN_TERMINATED if wait_semaphore is destroyed, KERN_INVALID_ARGUMENT for a null wait_semaphore, and KERN_INVALID_VALUE for a malformed wait_time.

functionsemaphore_wait_signal

extern kern_return_t semaphore_wait_signal(
	semaphore_t wait_semaphore,
	semaphore_t signal_semaphore
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/sync_sema.c
Atomically registers a wait on wait_semaphore and then signals signal_semaphore, so that no wakeup on signal_semaphore can be missed between the two operations; if a thread is blocked on signal_semaphore, the processor may be handed off to it directly. Returns the same codes as semaphore_wait: KERN_SUCCESS, KERN_ABORTED if interrupted, KERN_TERMINATED if wait_semaphore is destroyed, and KERN_INVALID_ARGUMENT for a null wait_semaphore.

functionsemaphore_signal_thread

extern kern_return_t semaphore_signal_thread(semaphore_t semaphore, thread_t thread)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/sync_sema.c
If the specified thread is blocked on the semaphore, it is awakened; if THREAD_NULL is supplied, any one waiting thread is awakened. When no such waiter exists, KERN_NOT_WAITING is returned and the semaphore is unchanged - unlike semaphore_signal, the count is never incremented. Returns KERN_INVALID_ARGUMENT for a null semaphore and KERN_TERMINATED if the semaphore has been destroyed.