note 118298 added to class.threaded
| From: | 312036773 at qq dot com | Date: | Wed, 11 Nov 2015 07:58:42 +0000 |
| Subject: | note 118298 added to class.threaded | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204135@lists.php.net to get a copy of this message | ||
<?php
class Wallet{
public $balance;
public function __construct($money){
$this->balance = $money;
}
public function getBalance(){
return $this->balance;
}
public function setBalance($value){
$this->balance = $value;
}
}
class MyThread extends Thread{
private $wallet;
private $std;
public function __construct($wallet,$std){
$this->wallet = $wallet;
$this->std = $std;
}
public function run(){
$this->synchronized(function($thread){
$hack = $this->wallet;
if($hack->getBalance() - 80 >0){
sleep(1);
$hack->setBalance($hack->getBalance() - 80);
echo $this->getThreadId() . "reduce 80 successful<br/>Current num isï¼"
. $hack->getBalance() . "<Br/>";
//Here is Wrong! The result is bool(false)????!!!!
var_dump($hack == $this->wallet);
}
else
echo $this->getThreadId() . "reduce fail<br/>Current num isï¼" .
$hack->getBalance() . "<br/>";
},$this->std);
}
}
$wallet = new Wallet(200);
$std = new stdClass();
for($x=0;$x<3;$x++){
$pool[] = new MyThread($wallet,$std);
$pool[$x]->start();
}
----
Server IP: 72.52.91.14
Probable Submitter: 60.27.237.187
----
Manual Page -- http://php.net/manual/en/class.threaded.php
Edit -- https://master.php.net/note/edit/118298
Del: integrated -- https://master.php.net/note/delete/118298/integrated
Del: useless -- https://master.php.net/note/delete/118298/useless
Del: bad code -- https://master.php.net/note/delete/118298/bad+code
Del: spam -- https://master.php.net/note/delete/118298/spam
Del: non-english -- https://master.php.net/note/delete/118298/non-english
Del: in docs -- https://master.php.net/note/delete/118298/in+docs
Del: other reasons-- https://master.php.net/note/delete/118298
Reject -- https://master.php.net/note/reject/118298
Search -- https://master.php.net/manage/user-notes.php