note 118553 deleted from class.thread by crell

From: Date: Mon, 04 Apr 2022 16:58:22 +0000
Subject: note 118553 deleted from class.thread by crell
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-218126@lists.php.net to get a copy of this message
Note Submitter: 312036773 at qq dot com ---- <?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();

« previous php.notes (#218126) next »