note 118516 added to threaded.lock
| From: | 312036773 at qq dot com | Date: | Fri, 18 Dec 2015 16:24:18 +0000 |
| Subject: | note 118516 added to threaded.lock | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204487@lists.php.net to get a copy of this message | ||
index.php
<?php
if (class_exists ( "Entity\My" )) {
$my = new Entity\My ( 200 );
}
if (class_exists ( "Entity\T" )) {
for($i = 0; $i < 3; $i ++) {
$t [] = new Entity\T ( $my );
}
}
foreach ($t as $item){
$item->start();
}
t.class.php
<?php
class T extends \Thread{
private $my;
public function __construct($my){
$this->my = $my;
}
public function run(){
$this->my->draw("120");
}
}
my.class.php
<?php
class My extends Thread{
private $balance;
public function __construct($balance){
$this->balance = $balance;
}
public function draw($cost){
$this->lock();
if($this->balance >= $cost){
usleep(500);
$this->balance -= $cost;
echo Thread::getCurrentThreadId() . "__get__${cost},now the balance
is:{$this->balance}<br/>";
}
else
echo Thread::getCurrentThreadId() . "__get fail__,now the balance is
:{$this->balance}<br/>";
$this->unlock();
}
}
----
Server IP: 72.52.91.14
Probable Submitter: 60.27.236.231
----
Manual Page -- http://php.net/manual/en/threaded.lock.php
Edit -- https://master.php.net/note/edit/118516
Del: integrated -- https://master.php.net/note/delete/118516/integrated
Del: useless -- https://master.php.net/note/delete/118516/useless
Del: bad code -- https://master.php.net/note/delete/118516/bad+code
Del: spam -- https://master.php.net/note/delete/118516/spam
Del: non-english -- https://master.php.net/note/delete/118516/non-english
Del: in docs -- https://master.php.net/note/delete/118516/in+docs
Del: other reasons-- https://master.php.net/note/delete/118516
Reject -- https://master.php.net/note/reject/118516
Search -- https://master.php.net/manage/user-notes.php