(PECL pthreads >= 2.0.0)
Threaded::synchronized — 同步控制
在發(fā)起調用的線程上下文中獲取對象同步鎖,然后同步執(zhí)行代碼塊
block
要執(zhí)行的代碼塊
...
傳送給代碼塊的不定長參數
代碼塊的返回值
示例 #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)