OpenSwoole\Atomic->wakeup

Latest version: pecl install openswoole-22.1.2 | composer require openswoole/core:22.1.5

Declaration

<?php OpenSwoole\Atomic->wakeup ( int $count = 0 )

Parameters

count

How many waiting processes to wakeup.

Return

Description

The Atomic can be used as a Lock for syncing between mutliple processes.

Wakeup other processes with wait status.

Atomic->wait and Atomic->wakeup can be used for synchronization between multiple processes. You should not use OpenSwoole\Atomic->wait within coroutine context.

Example

<?php
$lock = new OpenSwoole\Atomic;
if (pcntl_fork() > 0) {
    echo "master start\n";
    $lock->wait(1.5);
    echo "master end\n";
} else {
    echo "child start\n";
    sleep(1);
    $lock->wakeup();
    echo "child end\n";
}
Last updated on September 1, 2022