PHP Conference Japan 2024

Threaded::isRunning

(PECL pthreads >= 2.0.0)

Threaded::isRunning狀態偵測

描述

public Threaded::isRunning(): 布林值

判斷參考的物件是否正在執行

參數

此函式沒有參數。

回傳值

狀態的布林值指示

注意事項:

當物件執行 run 方法時,它被認為正在執行中

範例

範例 #1 偵測參考物件的狀態

<?php
class My extends Thread {
public function
run() {
$this->synchronized(function($thread){
if (!
$thread->done)
$thread->wait();
},
$this);
}
}
$my = new My();
$my->start();
var_dump($my->isRunning());
$my->synchronized(function($thread){
$thread->done = true;
$thread->notify();
},
$my);
?>

上述範例會輸出

bool(true)

新增註解

使用者貢獻的註解

此頁面沒有使用者貢獻的註解。
To Top