文字

Threaded::wait

(PECL pthreads >= 2.0.0)

Threaded::waitSynchronization

说明

public boolean Threaded::wait ([ integer $timeout ] )

让发起调用的线程上下文进入等待状态,直到收到其他线程的唤醒通知

参数

timeout

可选参数,等待时间,以毫秒计

返回值

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

范例

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)
上一篇: 下一篇: