Cond::wait
(PECL pthreads < 3.0.0)
Cond::wait — 等待
Warning
   
 pthreads v3 中已经将 Cond 类移除。
说明
   final 
   public 
   static 
   
   Cond::wait
    ( 
   int
    
  $condition
   
   , 
   int
    $mutex
   
   [, 
   int
    $timeout
  
  ] ) : bool进入条件变量等待状态。通过 timeout 参数可以设置等待超时时间。
参数
- 
condition
- 
     通过调用 Cond::create() 函数获得的条件变量句柄 
- 
mutex
- 
     通过调用 Mutex::create() 函数获得的互斥量,并且已经被调用者线程加锁。 
- 
timeout
- 
     等待超时,以毫秒为单位。 
返回值
布尔值,表示操作是否成功。
范例
Example #1 等待条件变量
<?php
/** 请注意,本示例会导致进程挂起 **/
$mutex = Mutex::create(true);
/** 不可以使用 new 关键字,因为 Cond 不是 PHP 对象 **/
$cond = Cond::create();
/** The caller must lock the associated Mutex before a call to broadcast **/
var_dump(Cond::wait($cond, $mutex));
/** 永远不要忘记销毁你创建的条件变量及互斥量 **/
Cond::destroy($cond);
Mutex::unlock($mutex);
Mutex::destroy($mutex);
?>
以上例程会输出:
int(49685473)