final class Sync (View source)

The Sync class provides access to low level synchronization primitives, mutex, condition variables, and allows the implementation of semaphores.

Synchronization for most applications is much better implemented using channels, however, in some cases authors of low level code may find it useful to be able to access these lower level mechanisms.

Methods

__construct(string|int|float|bool $value = null)

Shall construct a new synchronization object with no value Shall construct a new synchronization object containing the given scalar value

string|int|float|bool
get()

Shall atomically return the synchronization objects value

set(string|int|float|bool $value)

Shall atomically set the value of the synchronization object

bool
wait()

Shall wait for notification on this synchronization object

bool
notify(bool $all = null)

Shall notify one (by default) or all threads waiting on the synchronization object

__invoke(callable $block)

Shall exclusively enter into the critical code

Details

__construct(string|int|float|bool $value = null)

Shall construct a new synchronization object with no value Shall construct a new synchronization object containing the given scalar value

Parameters

string|int|float|bool $value

Exceptions

IllegalValue

string|int|float|bool get()

Shall atomically return the synchronization objects value

Return Value

string|int|float|bool

set(string|int|float|bool $value)

Shall atomically set the value of the synchronization object

Parameters

string|int|float|bool $value

Exceptions

IllegalValue

bool wait()

Shall wait for notification on this synchronization object

Return Value

bool

bool notify(bool $all = null)

Shall notify one (by default) or all threads waiting on the synchronization object

Parameters

bool $all

Return Value

bool

__invoke(callable $block)

Shall exclusively enter into the critical code

Parameters

callable $block