PHP 5.5.37 is released

Thread::join

(PECL pthreads >= 2.0.0)

Thread::joinSynchronization

Description

public boolean Thread::join ( void )

Causes the calling context to wait for the referenced Thread to finish executing

Parameters

This function has no parameters.

Return Values

A boolean indication of success

Examples

Example #1 Join with the referenced Thread

<?php
class My extends Thread {
    public function 
run() {
        
/* ... */
    
}
}
$my = new My();
$my->start();
/* ... */
var_dump($my->join());
/* ... */
?>

The above example will output:

bool(true)

add a note add a note

User Contributed Notes 1 note

up
-3
793722672 at qq dot com
8 months ago
/**
* 实现多线程的类
*/
class synchronized extends Thread
{
    public function run()
    {
        $daemon = new SendNoticeAction();
        $daemon->main();
    }

}
for ($i = 0; $i < 10; $i++) {
    $pool[] = new synchronized();
}
foreach ($pool as $work) {
    //在独立线程中执行 run 方法
    $work->start();
    while ($work->isRunning()) {
        usleep(10);
    }
    //让当前执行上下文等待被引用线程执行完毕
    $work->join();
}
To Top