unread
Hi internals.
The Fiber vote appears to have passed. Congratulations!
Now, while Fiber is a very nice feature, it has increased the severity of
MT's global state problems.
I have prepared an example using amphp. It is difficult to predict the
results of the following run, and there appears to be no guarantee that
consistency will be maintained.
<?php
require __DIR__ . '/vendor/autoload.php';
use function Amp\defer;
use function Amp\delay;
function task(int $i): void {
global $running;
while ($running) {
delay(250);
echo "${i} : " . `mt_rand()` . "\n";
}
}
mt_srand(1234);
$running = true;
defer(fn() => task(1));
defer(fn() => task(2));
defer(fn() => task(3));
defer(fn() => task(4));
delay(1000);
$running = false;
/*
Result:
1 : 411284887
4 : 1068724585
2 : 1335968403
3 : 1756294682
1 : 940013158
3 : 1314500282
4 : 1686544716
2 : 1656482812
1 : 1674985287
2 : 1848274264
3 : 585388171
4 : 323490420
4 : 593702477
3 : 426315791
2 : 1722007381
1 : 1750549071
*/
I have added a note to the RFC wiki about this issue. Also, the namespace
voting option has been removed, as Nikita has already provided a suitable
RFC.
https://wiki.php.net/rfc/object_scope_prng
Perhaps now is the time to discuss this proposal.
I would like to include this implementation in PHP 8.1's Fiber. If there is
no further discussion, I will move on to the voting phase.
Regards,
Go Kudo