note 116503 added to class.thread

From: Date: Wed, 14 Jan 2015 09:30:28 +0000
Subject: note 116503 added to class.thread
Groups: php.notes 
Request: Send a blank email to php-notes+get-201424@lists.php.net to get a copy of this message
<?php class demo extends Thread{ public $num = 0; public function __construct($num){ $this->num = $num+200; } public function run(){ //当执行start方法时,run会执行,所以没有直接调用run的方法 return $this->num; } } //时间计算开始 $t = microtime(true); for($i = 0 ;$i < 10 ; $i++){ //创建线程池 $pool[] = new demo($i); } foreach($pool as $work){ //在独立线程中执行 run 方法 $work->start(); } foreach($pool as $key=>$value){ //对象是否正在运行 while($value->isRunning()){ usleep(10); } //让当前执行上下文等待被引用线程执行完毕 if($value->join()){ $row[$key] = $value->num; } } //时间计算结束 $e = microtime(true); var_dump($row); echo '<br />'; echo ($e-$t); ---- Server IP: 72.52.91.14 Probable Submitter: 117.114.144.75 ---- Manual Page -- http://php.net/manual/en/class.thread.php Edit -- https://master.php.net/note/edit/116503 Del: integrated -- https://master.php.net/note/delete/116503/integrated Del: useless -- https://master.php.net/note/delete/116503/useless Del: bad code -- https://master.php.net/note/delete/116503/bad+code Del: spam -- https://master.php.net/note/delete/116503/spam Del: non-english -- https://master.php.net/note/delete/116503/non-english Del: in docs -- https://master.php.net/note/delete/116503/in+docs Del: other reasons-- https://master.php.net/note/delete/116503 Reject -- https://master.php.net/note/reject/116503 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#201424) next »