Thread::join
(PECL pthreads >= 2.0.0)
Thread::join — Synchronization
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)
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для управления процессами программ
- pthreads
- Функция Thread::detach() - Execution
- Функция Thread::getCreatorId() - Identification
- Функция Thread::getCurrentThread() - Identification
- Функция Thread::getCurrentThreadId() - Identification
- Функция Thread::getThreadId() - Identification
- Функция Thread::globally() - Execution
- Функция Thread::isJoined() - State Detection
- Функция Thread::isStarted() - State Detection
- Функция Thread::join() - Synchronization
- Функция Thread::kill() - Execution
- Функция Thread::start() - Execution
Коментарии
/**
* 实现多线程的类
*/
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();
}