liveBook · Manning

Semaphore

A semaphore is a synchronization primitive that uses a counter of available permits to coordinate operations or control concurrent access to a resource.

How 6 Manning books explain it

Python Concurrency with asyncio

A semaphore is a synchronization primitive that maintains a counter and permits a bounded number of execution contexts to access a resource concurrently.

How it is used
Limits concurrency and controls access to finite resources such as connection pools, APIs, CPUs, and subprocesses.
How deep it goes
Explains permit counting, blocking at zero, lock equivalence, async usage, and excess-release detection through BoundedSemaphore.
Examples
Uses asyncio tasks, limited API requests, database connections, and CPU-bound gpg subprocesses as concrete applications.
What you can do after
Apply asyncio.Semaphore or BoundedSemaphore to constrain concurrent operations and diagnose incorrect manual release logic.

Read how Python Concurrency with asyncio explains semaphore →

Software Design for Python Programmers

A Python Semaphore object controls concurrent access by maintaining a counter of available permits.

How it is used
Coordinates multithreaded access when multiple readers may share a resource but writers require exclusion.
How deep it goes
Explains permit counting, blocking, releasing, and reader-writer coordination through a worked Python simulation; defers broader performance concerns.
Examples
Uses a meter, technician writer threads, logger reader threads, Lock, Semaphore(3), simulated delays, and timestamped output.
What you can do after
Apply it via Python's threading module to limit simultaneous readers and protect shared resources from concurrent writes.

Read how Software Design for Python Programmers explains semaphore →

Learn Concurrent Programming with Go

A synchronization mechanism that controls concurrent access to a resource through a counter of available permits.

How it is used
Limits concurrent access to shared resources and records completion signals between goroutines.
How deep it goes
Implements permit accounting with condition variables, including Acquire and Release behavior, then applies it to completion and channel buffering.
Examples
Uses a limited database, a zero-permit task-completion signal, and capacity-controlled channel sending.
What you can do after
Build it from scratch with a permit counter and condition variable, then apply it to bounded access and completion signaling.

Read how Learn Concurrent Programming with Go explains semaphore →

The Coder Cafe

A semaphore is a synchronization mechanism maintaining a counter that limits or coordinates concurrent access to a resource.

How it is used
Coordinates access to shared resource pools when concurrent threads must stay within a capacity limit.
How deep it goes
Explains counters, decrement-and-increment signaling, capacity limits, and mutex contrasts, but does not provide implementation code.
Examples
Uses a five-space parking lot to model resource capacity, waiting, acquisition, and release.
What you can do after
Operate/configure bounded concurrent access by tracking available resources and signaling releases.

Read how The Coder Cafe explains semaphore →

Build an AI Agent (From Scratch)

A semaphore is a synchronization primitive that limits how many concurrent operations may enter a protected region.

How it is used
Limits concurrent API calls during asynchronous LLM requests and multi-model evaluation.
How deep it goes
Explains scoped acquisition and release, provider-specific limits, and tuning, without discussing semaphore internals.
Examples
Uses 100 concurrent LLM tasks with a limit of 10 and provider-specific limits in a GAIA evaluation.
What you can do after
Apply asyncio.Semaphore to bound concurrent requests and tune provider-specific limits.

Read how Build an AI Agent (From Scratch) explains semaphore →

Grokking Concurrency

A semaphore is a synchronization primitive that controls access to a resource while allowing multiple tasks to hold access concurrently.

How it is used
Controls concurrent access to a bounded shared resource while permitting several tasks to proceed simultaneously.
How deep it goes
Explains counters, blocking, waking, acquire-release behavior, mutex comparison, and a threaded Python implementation.
Examples
Uses a three-space parking garage, ten threads, parking permits, acquire-release operations, and a protected parked-car list.
What you can do after
Apply semaphores in Python to limit concurrent resource users and coordinate waiting tasks.

Read how Grokking Concurrency explains semaphore →

Also covered in

What to know first

Related concepts

Questions about semaphore

What is semaphore?

A semaphore is a synchronization primitive that uses a counter of available permits to coordinate operations or control concurrent access to a resource.

Which Manning books explain semaphore?

Python Concurrency with asyncio, Software Design for Python Programmers, Learn Concurrent Programming with Go, The Coder Cafe, Build an AI Agent (From Scratch) and Grokking Concurrency.

What should I know before learning semaphore?

Manning books that teach semaphore usually introduce locking, thread, task and async with first.

What is the difference between semaphore and locking?

A semaphore is a synchronization primitive that uses a counter of available permits to coordinate operations or control concurrent access to a resource. Locking is a synchronization technique that controls concurrent access to a shared resource or protected operation.

What kinds of semaphore are there?

Kinds of semaphore include binary semaphore and bounded semaphore.

What is semaphore a kind of?

Semaphore is a kind of synchronization object. A synchronization object is a programming construct that coordinates access or communication among concurrent threads.

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.