Threaded::synchronized

(PECL pthreads >= 2.0.0)

Threaded::synchronized同锟斤拷锟斤拷锟斤拷

说锟斤拷

public Threaded::synchronized ( Closure $block [, mixed $... ] ) : mixed

锟节凤拷锟斤拷锟斤拷玫锟斤拷叱锟斤拷锟斤拷锟斤拷锟斤拷谢锟饺★拷锟斤拷锟酵拷锟斤拷锟斤拷锟饺伙拷锟酵拷锟街达拷写锟斤拷锟斤拷

锟斤拷锟斤拷

block

要执锟叫的达拷锟斤拷锟�

...

锟斤拷锟酵革拷锟斤拷锟斤拷锟侥诧拷锟斤拷锟斤拷锟斤拷锟斤拷

锟斤拷锟斤拷值

锟斤拷锟斤拷锟侥凤拷锟斤拷值

锟斤拷锟斤拷

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)