Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Counter
- {
- public $maxCount = 50;
- private $count = 0;
- public function increase()
- {
- if ($this->count === $this->maxCount) {
- throw new \OutOfBoundsException;
- }
- $this->count++;
- }
- public function getCount()
- {
- return $this->count
- }
- }
- class Increasor implements Runnable
- {
- /** @var Counter */
- private $counter;
- public function __construct(Counter $counter)
- {
- $this->counter = $counter;
- }
- public function run()
- {
- while (TRUE) {
- try {
- $this->counter->increase();
- } catch (\utOfBoundsException $e) {
- break;
- }
- }
- }
- }
- $counter = new Couter();
- for ($i=0; $i < 3 ;$i++) {
- new Thread(new Increasor($counter)).start();
- }
Advertisement
Add Comment
Please, Sign In to add comment