Threads & Concurrency Models

POSIX threads (pthreads)

/ POSIX = PAHZ-icks; pthreads = PEE-threads /

When many different brands of car all put the steering wheel, accelerator, and brake in the same place, you can drive any of them without relearning. A standard does that for software: it fixes a common interface so the same program works across systems. Pthreads (POSIX threads) is that standard for threading on Unix-like systems — an agreed-upon set of function names and behaviors for creating and coordinating threads, so the same threaded C program compiles and runs on Linux, macOS, the BSDs, and more.

Concretely, pthreads is a specification (part of the POSIX standard) that defines an application programming interface, not a particular implementation — each OS provides its own library that obeys it. The core calls are few and learnable: pthread_create() starts a new thread running a function you name; pthread_join() makes the caller wait for another thread to finish and collect its result; pthread_exit() ends the calling thread. The same standard also defines the synchronization primitives threads need, such as mutexes (pthread_mutex_lock and pthread_mutex_unlock) and condition variables, though using those safely belongs to the separate topic of synchronization.

Why it matters: pthreads is the foundation many higher-level thread tools are built on, and on Linux a pthread maps one-to-one to a kernel thread, so it delivers true parallelism. Two honest cautions. First, an API is a contract about names and behavior, not the same thing as a system call — pthreads is a library that may use system calls underneath, and the line between the API and the kernel is itself a distinct idea. Second, pthreads gives you the tools to share data between threads but takes no responsibility for using them correctly; forget to lock and you get a race. The standard hands you a powerful, sharp instrument.

In C, you write pthread_create(&t, NULL, work, arg) to launch the function work() on a new thread, then later pthread_join(t, NULL) to wait for it to finish. The same two lines compile and behave the same on Linux and macOS — that portability is the whole point of a standard.

A portable thread API: same calls, many operating systems.

Pthreads is a specification and library, not itself a system call; the API/system-call boundary is a separate idea. And it provides locks but never enforces their use — correctness is still your job.

Also called
POSIX threadsthe pthreads APIIEEE 1003.1cPOSIX 執行緒標準