Skip to content

Glossary

Thread (Mach)

The Mach unit of execution. Schedulable, has CPU registers, runs inside a task's address space. POSIX threads are a layer on top.

A Mach thread is the smallest unit XNU can schedule onto a CPU. Every thread:

  • Lives inside exactly one task (whose address space it executes in).
  • Owns its own CPU state — register file, stack pointer, control registers.
  • Has a kernel stack used for syscall handling.
  • Carries a scheduling priority and policy.

apple-oss-distributions/xnuosfmk/kern/thread.hthread structure — the schedulable execution context.View on GitHub(line ) apple-oss-distributions/xnuosfmk/kern/sched_prim.cThe Mach scheduler — what picks the next thread to run.View on GitHub(line )

pthread_create in libpthread doesn't create a Mach thread directly; it calls bsdthread_create which calls into Mach's thread_create. The pthread_t you get back is a userspace handle layered on the Mach thread underneath.

The scheduler in XNU is multi-class: real-time, timeshare, fixed-priority, and idle, with quality-of-service (QoS) classes mapped on top (QOS_CLASS_USER_INTERACTIVE, QOS_CLASS_BACKGROUND, etc.) for libdispatch.

See also: task, Mach.