PHP - Threaded::wait 函数



Threaded::wait - 同步

语法

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

Threaded::wait() 函数可以使调用上下文等待来自引用对象的通知。

Threaded::wait() 函数可以返回一个布尔值,指示是否成功。

示例

<?php
   class My extends Thread {
      public function run() {
         /** cause this thread to wait **/
         $this->synchronized(function($thread) {
            if(!$thread->done)
               thread->wait();
         }, $this);
      }
   }
   $my = new My();
   $my->start();
   /** send notification to the waiting thread **/
   $my->synchronized(function($thread){
      $thread->done = true;
      $thread->notify();
   }, $my);
   var_dump($my->join());
?>
php_function_reference.htm
广告