PHP pthread doesnt seems to be multithreading -
please assist if possible. intended pull x amount of rows db, separating them arrays of 20 arrays , pass them thread processing simultaneously.
to ensure process working simultaneously created quick thread echo's out thread number counts 20. expected see results "1 @ 1" "2 @ 1". instead see first thread counts 20 before second thread begins execute. ie "1 @ 1" ... "1 @ 20" "2 @ 1".
<?php class helloworld extends thread { public function __construct($arg){ $this->arg = $arg; } public function run(){ if($this->arg){ ($i=1;$i<=20;$i++){ echo $this->arg ." @ "; echo $i." "; sleep(1); } } } }
?>
then call use
for ($i=1;$i<=$num_threads;$i++){ $thread[$i] = new helloworld($i); if($thread[$i]->start()) $thread[$i]->join(); }
is seeing correct? or doing stupid here?
thanks
rob
the pthread's join() function waits thread specified terminate. if thread has terminated, pthread's join() function returns immediately. thread specified must joinable.
so, waiting each started thread terminate before moving on in loop.
Comments
Post a Comment