note 126410 added to class.parallel-runtime

From: Date: Fri, 10 Sep 2021 16:58:34 +0000
Subject: note 126410 added to class.parallel-runtime
Groups: php.notes 
Request: Send a blank email to php-notes+get-216944@lists.php.net to get a copy of this message
<?php // make sure that is really parallel execution // you will get different output on each script run use parallel\{Channel, Runtime}; const THREADS_COUNT = 5; const THREADS_I_MAX = 10; $ch = new Channel(); // executed within thread $task = static function (Channel $ch, int $i, int $to): void { echo "[enter: $i]\n"; for ($j = 0; $j < $to; $j++) { $ch->send($i); } echo "[exit: $i]\n"; }; // creating a few threads $runtimeList = []; for ($i = 0; $i < THREADS_COUNT; $i++) { $runtimeList[] = new Runtime(); } // run all threads foreach ($runtimeList as $i => $runtime) { echo "[run: $i]\n"; $runtime->run($task, [$ch, $i, THREADS_I_MAX]); } // reading messages from channel $queue = ''; for ($i = 0; $i < THREADS_COUNT * THREADS_I_MAX; $i++) { $queue .= $ch->recv(); } $ch->close(); echo $queue . PHP_EOL; ---- Server IP: 45.112.84.4 Probable Submitter: 45.112.85.242 (proxied: 176.104.221.149) ---- Manual Page -- https://php.net/manual/en/class.parallel-runtime.php Edit -- https://main.php.net/note/edit/126410 Del: integrated -- https://main.php.net/note/delete/126410/integrated Del: useless -- https://main.php.net/note/delete/126410/useless Del: bad code -- https://main.php.net/note/delete/126410/bad+code Del: spam -- https://main.php.net/note/delete/126410/spam Del: non-english -- https://main.php.net/note/delete/126410/non-english Del: in docs -- https://main.php.net/note/delete/126410/in+docs Del: other reasons-- https://main.php.net/note/delete/126410 Reject -- https://main.php.net/note/reject/126410 Search -- https://main.php.net/manage/user-notes.php

« previous php.notes (#216944) next »