The problem with Pthread class

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
SiamakHadadi
Forum Newbie
Posts: 1
Joined: Sun Apr 27, 2014 5:33 pm

The problem with Pthread class

Post by SiamakHadadi »

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.

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;
?>

Post Reply