Last active
May 27, 2020 07:25
-
-
Save PJZ9n/baebb82924faaeb6e9b13634fc2d12a2 to your computer and use it in GitHub Desktop.
pthreadsを使ったマルチスレッディングのテスト
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <?php | |
| declare(strict_types=1); | |
| class ExampleThread extends Thread | |
| { | |
| /** @var int */ | |
| private $id; | |
| public function __construct(int $id) | |
| { | |
| $this->id = $id; | |
| } | |
| public function run() | |
| { | |
| echo "THREAD #{$this->id} PROCESS" . PHP_EOL; | |
| sleep(1); | |
| } | |
| } | |
| $pool = new Pool(5); | |
| for ($i = 0; $i < 5; $i++) { | |
| echo "THREAD #{$i} START" . PHP_EOL; | |
| $pool->submit(new ExampleThread($i)); | |
| } | |
| while ($pool->collect()) { | |
| // | |
| } | |
| $pool->shutdown(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment