0 follower

Interface Yiisoft\Mutex\MutexInterface

Implemented byYiisoft\Mutex\Mutex

The Mutex allows mutual execution of concurrent processes in order to prevent "race conditions".

This is achieved by using a "lock" mechanism. Each possibly concurrent process cooperates by acquiring a lock before accessing the corresponding data.

Usage example:

$mutex = new MyMutex('critical_logic');

if (!$mutex->acquire(1000)) {
    throw new \Yiisoft\Mutex\Exception\MutexLockedException('Unable to acquire the "critical_logic" mutex.');
}

// ...
// business logic execution
// ...

$mutex->release();

Public Methods

Hide inherited methods

Method Description Defined By
acquire() Acquires a lock. Yiisoft\Mutex\MutexInterface
release() Releases a lock. Yiisoft\Mutex\MutexInterface

Method Details

Hide inherited methods

acquire() public abstract method

Acquires a lock.

public abstract boolean acquire ( integer $timeout 0 )
$timeout integer

Time (in seconds) to wait for lock to be released. Defaults to zero meaning that method will return false immediately in case lock was already acquired.

return boolean

Whether a lock is acquired.

                public function acquire(int $timeout = 0): bool;

            
release() public abstract method

Releases a lock.

public abstract void release ( )

                public function release(): void;