liveBook · Manning

POSIX Threads API

As explained in Refactoring to Rust

POSIX threads are a standardized operating-system threading interface for creating and managing native threads.

POSIX threads, or pthreads, provide operating-system-managed threads for concurrent work. Unlike green threads maintained by a language or runtime, these threads are scheduled by the operating system and can provide parallelism when multiple processing units are available. section 8.4

Threaded computation

A Python program can submit separate Mandelbrot calculations to a four-worker ThreadPoolExecutor and await them alongside asyncio tasks. This tests whether CPU-bound or externally blocked work benefits from operating-system threads; asynchronous execution alone may show little improvement. section 8.4

Figure 8.5 Within our box, we do not know how many crushers we have, and we have no guarantee of the order. Adding more crushers adds more throughput.
figure

The crusher analogy visualizes how additional operating-system workers can increase throughput while completion order remains unpredictable. section 8.4

How Refactoring to Rust covers it

How deep it goes
Defines operating-system and green threads, then demonstrates Python thread submission without detailing the pthreads API.
Examples
Uses a can-crusher throughput analogy and a Python Mandelbrot ThreadPoolExecutor example.
What it assumes
Assumes basic familiarity with Python asynchronous execution while distinguishing concurrency from parallelism.
What you can do after
Evaluate threaded computation with Python’s ThreadPoolExecutor and compare its measured improvement against asynchronous execution.
How it connects
Connects POSIX threads with concurrency, parallelism, green threads, asyncio, and operating-system scheduling.

Also explained in

Compare how 2 books explain POSIX Threads API →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Refactoring to Rust. The section links point to the parts of the book it draws on.