This is automatic generated document for things in Swow\Sync\ThreadBarrier class

Class ThreadBarrier

A reusable barrier for a fixed number of OS threads.

wait() blocks the whole OS thread, not only the current coroutine. Use it only in a worker thread that runs one coroutine. A cycle releases when count threads wait. The barrier works in one process only.

Methods

Method __construct

public function __construct ( int $count )

Create a barrier.

Param int $count number of threads in one cycle

Throws \ValueError when the count is out of range Throws SyncException when the barrier is already constructed

Method __debugInfo

public function __debugInfo ( ) : array

Return debug information.

Method __serialize

public function __serialize ( ) : array

Serialize the barrier by shared object id.

Method __unserialize

public function __unserialize ( array $data ) : void

Restore the barrier from a shared object id.

Method getCount

public function getCount ( ) : int

Return the number of threads in one cycle.

Method getWaiting

public function getWaiting ( ) : int

Return the number of threads currently waiting.

Method wait

public function wait ( int $timeout ) : bool

Wait for the other threads.

this method blocks the whole OS thread

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

Returns bool false on timeout

Throws SyncException when the caller cannot wait


Copyright 2022 the Swow contributors