Replies: 1 comment
-
It does not support function names or closures; creating a thread requires passing the path to the PHP script file, similar to Node.js's worker threads. <?php
use Swoole\Thread;
use Swoole\Thread\Atomic;
use Swoole\Thread\Atomic\Long;
$args = Thread::getArguments();
$c = 4;
$n = 128;
if (empty($args)) {
$threads = [];
$a1 = new Atomic;
$a2 = new Long;
for ($i = 0; $i < $c; $i++) {
$threads[] = new Thread(__FILE__, $i, $a1, $a2);
}
for ($i = 0; $i < $c; $i++) {
$threads[$i]->join();
}
var_dump($a1->get(), $a2->get());
} else {
$a1 = $args[1];
$a2 = $args[2];
$a1->add(3);
$a2->add(7);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
Is it planned to open a Thread with a closure, vs from an actual file?
Thank you,
Hans
Beta Was this translation helpful? Give feedback.
All reactions