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