-
Notifications
You must be signed in to change notification settings - Fork 7.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global tick API support #4171
global tick API support #4171
Conversation
I am one of developers of Swoole(https://github.com/swoole/swoole-src) from china, with the request we can implement following, including involves many php files. <?php
$max_msec = 10;
Co::set(['max_exec_msec' => $max_msec]);
$start = microtime(true);
echo "start\n";
$flag = 1;
go(function () use (&$flag, $max_msec) {
echo "coro 1 start to loop\n";
$i = 0;
while ($flag) {
$i++;
}
echo "coro 1 can exit\n";
});
$end = microtime(true);
$msec = ($end - $start) * 1000;
go(function () use (&$flag) {
echo "coro 2 set flag = false\n";
$flag = false;
});
echo "end\n";
?>
--EXPECTF--
start
coro 1 start to loop
coro 2 set flag = false
end
coro 1 can exit |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This patch has uses spaces instead of tabs, please fix that.
The function body is missing ZEND_API.
The new CG(ticks) should be initialized before use.
Thank you so much for your reply, I have modified the request as your help, please help review again. |
I have updated the request just now and using a |
99d1fe9
to
1dc2695
Compare
Using a global variable would not be thread-safe, would it? An ABI incompatibility due to introducing CG(ticks) in PHP 8 (or even 7.4) would be permissible. |
@cmb69 I think it is thread-safe, only call |
Adding this API so we can set a global default ticks number that can be used in every php file, avoiding set
declare(ticks=N)
at the beginning of each file many times.Please considering this request, it is so important to us, we have used
tick
to implementedpreemptive scheduling
for Swoole Coroutine, it is bad to setdeclare(ticks=N)
in each php file. we can usezend_set_global_tick
API in our extension by once with a default value.