PHP - Threaded::notifyOne() 函数



Threaded::notifyOne - 同步

语法

public boolean Threaded::notifyOne( void )

Threaded::notifyOne() 函数可以向引用的对象发送通知。它至少会解阻塞一个被阻塞的线程。

Threaded::notifyOne() 函数没有任何参数,并可以返回一个布尔值指示成功与否。

示例

<?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->notifyOne();
   }, $my);
   var_dump($my->join());
?>
php_function_reference.htm
广告