SyncMutex
class SyncMutex (View source)
SyncMutex
A cross-platform, native implementation of named and unnamed countable mutex objects. A mutex is a mutual exclusion object that restricts access to a shared resource (e.g. a file) to a single instance. Countable mutexes acquire the mutex a single time and internally track the number of times the mutex is locked. The mutex is unlocked as soon as it goes out of scope or is unlocked the same number of times that it was locked.
Methods
Constructs a new SyncMutex object
Waits for an exclusive lock
Unlocks the mutex
Details
__construct(string $name)
Constructs a new SyncMutex object
Constructs a named or unnamed countable mutex.
bool
lock(int $wait = -1)
Waits for an exclusive lock
Obtains an exclusive lock on a SyncMutex object. If the lock is already acquired, then this increments an internal counter.
bool
unlock(bool $all = false)
Unlocks the mutex
Decreases the internal counter of a SyncMutex object. When the internal counter reaches zero, the actual lock on the object is released.