note 118553 added to class.thread
| From: | 312036773 at qq dot com | Date: | Sun, 27 Dec 2015 16:38:20 +0000 |
| Subject: | note 118553 added to class.thread | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-204545@lists.php.net to get a copy of this message | ||
<?php
class STD extends Thread{
public function put(){
$this->synchronized(function(){
for($i=0;$i<7;$i++){
printf("%d\n",$i);
$this->notify();
if($i < 6)
$this->wait();
else
exit();
sleep(1);
}
});
}
public function flush(){
$this->synchronized(function(){
for($i=0;$i<7;$i++){
flush();
$this->notify();
if($i < 6)
$this->wait();
else
exit();
}
});
}
}
class A extends Thread{
private $std;
public function __construct($std){
$this->std = $std;
}
public function run(){
$this->std->put();
}
}
class B extends Thread{
private $std;
public function __construct($std){
$this->std = $std;
}
public function run(){
$this->std->flush();
}
}
ob_end_clean();
echo str_repeat(" ", 1024);
$std = new STD();
$ta = new A($std);
$tb = new B($std);
$ta->start();
$tb->start();
----
Server IP: 72.52.91.14
Probable Submitter: 221.198.61.71
----
Manual Page -- http://php.net/manual/en/class.thread.php
Edit -- https://master.php.net/note/edit/118553
Del: integrated -- https://master.php.net/note/delete/118553/integrated
Del: useless -- https://master.php.net/note/delete/118553/useless
Del: bad code -- https://master.php.net/note/delete/118553/bad+code
Del: spam -- https://master.php.net/note/delete/118553/spam
Del: non-english -- https://master.php.net/note/delete/118553/non-english
Del: in docs -- https://master.php.net/note/delete/118553/in+docs
Del: other reasons-- https://master.php.net/note/delete/118553
Reject -- https://master.php.net/note/reject/118553
Search -- https://master.php.net/manage/user-notes.php