liveBook · Manning

Reentrant lock

A reentrant lock is a mutual-exclusion lock that its owning thread can acquire repeatedly, requiring a matching release for each acquisition.

How 2 Manning books explain it

Python Concurrency with asyncio

A reentrant lock is a synchronization lock that its owning thread can acquire multiple times, requiring a matching release for each acquisition.

How it is used
Prevents recursive or nested same-thread lock acquisition from hanging while synchronizing shared data in threaded programs.
How deep it goes
Explains recursive acquisition, matching release, and internal counting, but defers implementation details beyond the recursion count.
Examples
Demonstrates recursive list summation and a thread-safe integer list with nested locked method calls.
What you can do after
Diagnose/debug with it by recognizing self-deadlock and replacing Lock with threading.RLock when same-thread reentry is required.

Read how Python Concurrency with asyncio explains reentrant lock →

Advanced Algorithms and Data Structures

A reentrant lock is a lock that allows the thread holding it to acquire it repeatedly, tracking nested acquisitions with a counter until matching releases occur.

How it is used
Coordinates concurrent cache-method access while allowing flexible read-versus-write locking.
How deep it goes
Defines locking and demonstrates same-thread reacquisition, but defers detailed lock internals and deadlock prevention.
Examples
Uses concurrent set calls and a set-to-evictOneEntry call chain to illustrate waiting and nested lock acquisition.
What you can do after
Apply it via Java's ReentrantReadWriteLock when nested cache operations require flexible synchronization.

Read how Advanced Algorithms and Data Structures explains reentrant lock →

Related concepts

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.