Threaded::notify

(PECL pthreads >= 2.0.0)

Threaded::notifySynchronisation

Description

public function Threaded::notify(): bool

Envoie une notification à l'objet référencé

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Cette fonction retourne true en cas de succès ou false si une erreur survient.

Exemples

Exemple #1 Notifications et attente

<?php
class My extends Thread {
    public function run() {
        /** fait que le thread patiente **/
        $this->synchronized(function($thread){
            if (!$thread->done)
                $thread->wait();
        }, $this);
    }
}
$my = new My();
$my->start();
/** envoie la notification au thread qui attend **/
$my->synchronized(function($thread){
    $thread->done = true;
    $thread->notify();
}, $my);
var_dump($my->join());
?>

L'exemple ci-dessus va afficher :

bool(true)