cii-text-analysis/vendor/amphp/sync/docs/semaphore.md
Jéremy Munsch f68d2ac333
premier poc
2026-02-11 08:24:04 +01:00

891 B

title permalink
Semaphore /semaphore

Semaphores are another synchronization primitive in addition to mutual exclusion.

Instead of providing exclusive access to a single party, they provide access to a limited set of N parties at the same time. This makes them great to control concurrency, e.g. limiting an HTTP client to X concurrent requests, so the HTTP server doesn't get overwhelmed.

Similar to Mutex, Lock instances can be acquired using Semaphore::acquire(). Please refer to the Mutex documentation for additional usage documentation, as they're basically equivalent except for the fact that Mutex is always a Semaphore with a count of exactly one party.

In many cases you can use concurrent iterators instead of directly using a Semaphore.