Threaded::notify

(PECL pthreads >= 2.0.0)

Threaded::notify同步控制

说明

public Threaded::notify ( void ) : bool

向对象发送唤醒通知

参数

此函数没有参数。

返回值

布尔值,表示操作是否成功

范例

Example #1 等待和唤醒

<?php
class My extends Thread {
    public function 
run() {
        
/** 让线程等待 **/
        
$this->synchronized(function($thread){
            if (!
$thread->done)
                
$thread->wait();
        }, 
$this);
    }
}
$my = new My();
$my->start();
/** 向处于等待状态的线程发送唤醒通知 **/
$my->synchronized(function($thread){
    
$thread->done true;
    
$thread->notify();
}, 
$my);
var_dump($my->join());
?>

以上例程会输出:

bool(true)