Threaded::notify

(PECL pthreads >= 2.0.0)

Threaded::notify同步控制

說明

public Threaded::notify(): bool

向?qū)ο蟀l(fā)送喚醒通知

參數(shù)

此函數(shù)沒有參數(shù)。

返回值

成功時返回 true, 或者在失敗時返回 false。

范例

示例 #1 等待和喚醒

<?php
class My extends Thread {
    public function 
run() {
        
/** 讓線程等待 **/
        
$this->synchronized(function($thread){
            if (!
$thread->done)
                
$thread->wait();
        }, 
$this);
    }
}
$my = new My();
$my->start();
/** 向處于等待狀態(tài)的線程發(fā)送喚醒通知 **/
$my->synchronized(function($thread){
    
$thread->done true;
    
$thread->notify();
}, 
$my);
var_dump($my->join());
?>

以上例程會輸出:

bool(true)