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
廣告