Threaded::notifyOne

(PECL pthreads >= 3.0.0)

Threaded::notifyOneSincronizar

Descripción

public 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 tiene parámetros.

Valores devueltos

Devuelve true en caso de éxito o false en caso de 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 resultado del ejemplo sería:

bool(true)

add a note

User Contributed Notes

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