(PECL pthreads >= 2.0.0)
Threaded::wait — 同步
timeout
以微秒為單位的選用逾時時間
範例 #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)