©
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
(PECL pthreads >= 2.0.0)
Thread::join — 同步
让当前执行上下文等待被引用线程执行完毕
此函数没有参数。
布尔值,表示操作成功与否
Example #1 加入线程
<?php
class My extends Thread {
public function run () {
}
}
$my = new My ();
$my -> start ();
var_dump ( $my -> join ());
?>
以上例程会输出:
bool(true)
[#1] 793722672 at qq dot com [2015-10-10 02:37:29]
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();
}