Why can't php pthread modify an object? -


i'm using php5.4, , wirte following code test. pass object worker thread, , try modify object in thread, doesn'g work expected.

<?php  class workerthread extends thread {      var $foo = null;      public function __construct($foo) {         $this->foo = $foo;     }         public function run() {         echo "thread started.\n";         $this->foo->val = 2;         echo "\n";         echo $this->foo->val;         echo "\n";         echo "thread exit${val}.\n";     }     }     class {     var $val = 1; }     $foo = new a();  var_dump($foo);  $thread = new workerthread($foo); $thread->start(); sleep(1);  var_dump($foo);  $foo2 = $foo; $foo2->val = 3;  var_dump($foo);  ?>   

this output get:

object(a)#1 (1) {   ["val"]=>   int(1) } thread started.  1  # expect 2 here thread exit. object(a)#1 (1) {   ["val"]=>   int(1)    # expect 2 here } object(a)#1 (1) {   # expected   ["val"]=>   int(3) } 

if can't share objects between thread, mutex, cond designed for?


Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -