www.webdeveloper.com
Results 1 to 5 of 5

Thread: The problem with Pthread class

Hybrid View

  1. #1
    Join Date
    Apr 2014
    Posts
    3

    Question The problem with Pthread class

    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.

    PHP Code:
    <?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;
    ?>

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,334
    What is the exact error you are getting?
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

  3. #3
    Join Date
    Apr 2014
    Posts
    3
    hi & tank you very much.

    The main problem is, I can't access to
    PHP Code:
    [$ temp]; 
    in outside the class ...

    in class i can "echo $j[1];" and output = 1001

    but

    Outside the the class:
    i cant, and have error like this:
    Code:
    Catchable fatal error: Object of class my could not be converted to integer in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\test\test3.php on line 30
    my output:
    PHP Code:
    1001 /* in my class*/
    1002 /* in my class*/

    Catchable fatal errorObject of class my could not be converted to integer in C:\Program Files\EasyPHP-DevServer-14.1VC9\data\localweb\test\test3.php on line 30 /* outside of my class*/ 

  4. #4
    Join Date
    Dec 2002
    Location
    Seattle, WA
    Posts
    1,843
    you are trying to add my class to my class
    PHP Code:
    $sum $j[0] + $j[1]; 
    try
    PHP Code:
    $sum $j[0]->arg $j[1]->arg

  5. #5
    Join Date
    Apr 2014
    Posts
    3
    Thank you very much for your answer.

    with proposed code my output: = > 3

    But I am looking for = > 2003

    I think,There is not accessible outside of class

    I had to change my own question:

    To be part of a student project should do something like the following:

    8 threads in a three-dimensional array is sorted.
    In the first step, each 8 threads use for 8 act (Like: act sum)
    In the second step 4 threads to be use for 4 act (Like: act sum)

    With these conditions,
    The previous code can not be used
    now I have no idea for it...

    Can you Help me, please
    How do I sort threads in array?
    and then access the threads with array value...
    like: $array[1] -> thread1 do...

    Unfortunately in this case, there is no source of my official language
    And my English is very poor,
    But happy to answer my questions I got here.
    Thank you very much.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles