CascadiaPHP 2024

Threaded::isRunning

(PECL pthreads >= 2.0.0)

Threaded::isRunning状态检测

说明

public Threaded::isRunning(): bool

对象是否正在运行

参数

此函数没有参数。

返回值

表示运行状态的布尔值

注意:

如果对象的 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)

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top