This is automatic generated document for things in Swow\Mutex class

Class Mutex

A mutex that works across threads.

The mutex is not recursive. The owner is a thread. A mutex stays locked when the owner thread exits. Do not destroy a locked mutex. Destruction of a locked mutex emits a warning.

Methods

Method __construct

public function __construct ( )

Create a mutex.

Method __debugInfo

public function __debugInfo ( ) : array

Return debug information.

Method __serialize

public function __serialize ( ) : array

Serialize the mutex by shared object id.

The serialized form does not copy the mutex state.

Throws \Swow\SyncException when the mutex is not constructed.

Method __unserialize

public function __unserialize ( array $data ) : void

Restore the mutex from a shared object id.

Throws \Swow\SyncException when the data is invalid or the object is gone.

Method lock

public function lock ( int $timeout ) : bool

Take the mutex.

In a coroutine, this method suspends the current coroutine when the mutex is held. Do not lock the same mutex twice from one thread. The second call waits and can deadlock.

context switching may happen here

Param int $timeout timeout in milliseconds, -1 waits forever

Returns bool false on timeout

Throws \Swow\SyncException when the caller cannot wait for the mutex.

Method unlock

public function unlock ( ) : void

Release the mutex.

The caller must hold the mutex.

Throws \Swow\SyncException when the caller does not hold the mutex.


Copyright 2022 the Swow contributors