The problem with Pthread class
Posted: Sun Apr 27, 2014 5:49 pm
Hi everyone
I have written a piece of code like the following
I used the front of the class: http://www.php.net/manual/en/book.pthreads.php
The goal is the end result is the sum = 2003
But I get an error message.
Is it possible to modify this piece of code for me.
Thank you And sorry for my illiteracy.
I have written a piece of code like the following
I used the front of the class: http://www.php.net/manual/en/book.pthreads.php
The goal is the end result is the sum = 2003
But I get an error message.
Is it possible to modify this piece of code for me.
Thank you And sorry for my illiteracy.
Code: Select all
<?php
class my extends Thread {
public function __construct($arg){
$this->arg = $arg;
}
public function run(){
if($this->arg){
$temp = $this->arg;
$i = ($this->arg) + 1000;
echo $i;
$j[$temp] = $i;
echo '<br>';
}
}
}
$j = array(
new my('1'), new my('2')
);
$thread = $j[0];
$thread->start();
$thread->join();
$thread = $j[1];
$thread->start();
$thread->join();
$sum = $j[0] + $j[1];
echo $sum;
?>