| Primitive | Purpose |
|---|---|
| Mutex |
Mutual exclusion lock: only one thread may hold it at a time.
Other threads block on |
| Recursive mutex | Like a mutex but the same thread may acquire it multiple times without deadlocking; must release it the same number of times. |
| Read/write mutex | Allows many concurrent readers or exactly one writer. Improves throughput when reads heavily outnumber writes. |
| Semaphore | A counter that allows up to N threads to proceed simultaneously. Used to limit concurrency (e.g., a pool of N database connections). |
| Condition variable |
Lets a thread sleep until a predicate becomes true. Always used with a mutex:
the thread atomically releases the mutex and sleeps; it reacquires the mutex
before returning from |
| Spinlock | Busy-waits in a loop rather than yielding to the scheduler. Efficient only when the wait is expected to be very short (microseconds); wastes CPU on longer waits. |
| Atomic operation | Hardware-guaranteed indivisible read-modify-write on a single word. Lock-free; used for flags, counters, and reference counts. |
| Barrier / latch | Blocks a group of threads until all have reached the barrier, then releases them together. Useful for phased parallel algorithms. |
| Language | Thread type | Key synchronization and safety |
|---|---|---|
| Rust |
|
|
| C++ |
|
|
| C# |
|
|
| Python |
|
|
| Language | Repositories | Interface |
|---|---|---|
| Rust |
RustThreadPool RustBlockingQueue |
|
| C++ |
ThreadPool CppBlockingQueue |
|
| C# | CsBlockingQueue |
ThreadPool: |
| Python | none yet |