略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Threaded::isRunning

2024-04-29

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 noteadd a note

User Contributed Notes

There are no user contributed notes for this page.

官方地址:https://www.php.net/manual/en/thread.isrunning.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3