Threaded::notifyOne

(PECL pthreads >= 3.0.0)

Threaded::notifyOneSincronizar

Descripción

public function Threaded::notifyOne(): bool

Envía una notificación al objeto referenciado. Esto desbloquea al menos uno de los threads bloqueados (a diferencia de desbloquearlos todos, como ocurre con Threaded::notify()).

Parámetros

Esta función no contiene ningún parámetro.

Valores devueltos

Esta función retorna true en caso de éxito o false si ocurre un error.

Ejemplos

Ejemplo #1 Notificaciones y espera

<?php
class My extends Thread {
    public function run() {
        /** causa que este thread espere **/
        $this->synchronized(function($thread){
            if (!$thread->done)
                $this->wait();
        }, $this);
    }
}
$my = new My();
$my->start();
/** envía una notificación al thread en espera **/
$my->synchronized(function($thread){
    $thread->done = true;
    $thread->notifyOne();
}, $my);
var_dump($my->join());
?>

El ejemplo anterior mostrará:

bool(true)
add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top