Threaded::wait

(PECL pthreads >= 2.0.0)

Threaded::waitSynchronisation

Description

public Threaded::wait ([ int $timeout ] ) : bool

Fera attendre le contexte appelant une notification depuis l'objet référencé.

Liste de paramètres

timeout

Un délai d'attente maximal optionnel, en microsecondes.

Valeurs de retour

Un booléen indiquant le succès.

Exemples

Exemple #1 Notifications et attente

<?php
class My extends Thread {
    public function 
run() {
        
/** Fait patienter ce thread **/
        
$this->synchronized(function($thread){
            if (!
$thread->done)
                
$thread->wait();
        }, 
$this);
    }
}
$my = new My();
$my->start();
/** Envoi 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)