#include <kern/thread.h>

kern/thread.h Kernel.framework

includes: Kernel/mach/kern_return.h, mach/mach_types.h, Kernel/mach/mach_param.h, mach/message.h, Kernel/mach/boolean.h, mach/vm_param.h, Kernel/mach/thread_info.h, Kernel/mach/thread_status.h, Kernel/mach/exception_types.h, kern/kern_types.h, vm/vm_kern.h, sys/cdefs.h, sys/_types/_size_t.h
7 functions

functionthread_has_thread_name

extern boolean_t thread_has_thread_name(thread_t th)
@function thread_has_thread_name @abstract Checks if a thread has a name. @discussion This function takes one input, a thread, and returns a boolean value indicating if that thread already has a name associated with it. @param th The thread to inspect. @result TRUE if the thread has a name, FALSE otherwise.

functionthread_set_thread_name

extern void thread_set_thread_name(thread_t th, const char* name)
@function thread_set_thread_name @abstract Set a thread's name. @discussion This function takes two input parameters: a thread to name, and the name to apply to the thread. The name will be copied over to the thread in order to better identify the thread. If the name is longer than MAXTHREADNAMESIZE - 1, it will be truncated. @param th The thread to be named. @param name The name to apply to the thread.

functioncurrent_thread

__pure2
extern thread_t current_thread(void)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/arm64/machine_routines.c
Returns the currently executing thread. No reference is taken; the value is read from per-CPU/thread register state.

functionthread_tid

__pure2
extern uint64_t thread_tid(thread_t thread)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/thread.c
Returns the system-wide unique 64-bit id of the thread, or 0 for THREAD_NULL. The id is assigned at thread creation and never reused for the life of the boot.

functionthread_reference

extern void thread_reference(thread_t thread)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/thread.c
Takes a reference on the thread, preventing the thread structure from being freed. A THREAD_NULL argument is ignored. Release with thread_deallocate.

functionthread_deallocate

extern void thread_deallocate(thread_t thread)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/thread.c
Releases a reference on the thread; when the last reference is dropped the thread structure and its associated resources are freed (the thread must already have terminated). A THREAD_NULL argument is ignored.

functionkernel_thread_start

extern kern_return_t kernel_thread_start(
	thread_continue_t continuation,
	void *parameter,
	thread_t *new_thread
)
claude-fable-5, 2026-08-24 · not from Apple sources · verified against xnu osfmk/kern/thread.c
Creates and starts a kernel thread that begins execution at continuation with the given parameter, at default kernel priority. On success returns KERN_SUCCESS and a reference to the new thread in *new_thread; the caller is responsible for releasing it with thread_deallocate. Returns KERN_FAILURE if the kernel task is terminating and KERN_RESOURCE_SHORTAGE if the thread cannot be allocated.