Skip to content

Commit a3ad077

Browse files
committed
+ shutdown_destructors_async Support for concurrent iteration of the global variable table
1 parent 560f50d commit a3ad077

File tree

3 files changed

+10
-5
lines changed

3 files changed

+10
-5
lines changed

coroutine.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -774,6 +774,9 @@ ZEND_STACK_ALIGNED void async_coroutine_execute(zend_fiber_transfer *transfer)
774774
// The scheduler coroutine always terminates into the main execution flow.
775775
//
776776
if (UNEXPECTED(&coroutine->coroutine == ZEND_ASYNC_SCHEDULER)) {
777+
778+
ZEND_ASYNC_SCHEDULER = NULL;
779+
777780
if (transfer != ASYNC_G(main_transfer)) {
778781

779782
if (UNEXPECTED(Z_TYPE(transfer->value) == IS_OBJECT)) {

scheduler.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,10 +348,8 @@ static void async_scheduler_dtor(void)
348348
zend_hash_destroy(&ASYNC_G(coroutines));
349349
zend_hash_init(&ASYNC_G(coroutines), 0, NULL, NULL, 0);
350350

351-
ZEND_ASYNC_CURRENT_COROUTINE = NULL;
352351
ZEND_ASYNC_GRACEFUL_SHUTDOWN = false;
353352
ZEND_ASYNC_SCHEDULER_CONTEXT = false;
354-
ZEND_ASYNC_DEACTIVATE;
355353

356354
zend_exception_restore();
357355
}
@@ -656,6 +654,9 @@ void async_scheduler_main_coroutine_suspend(void)
656654

657655
switch_to_scheduler(NULL);
658656

657+
ZEND_ASYNC_CURRENT_COROUTINE = NULL;
658+
ZEND_ASYNC_DEACTIVATE;
659+
659660
if (ASYNC_G(main_transfer)) {
660661
efree(ASYNC_G(main_transfer));
661662
ASYNC_G(main_transfer) = NULL;

tests/spawn/013-spawn_in_shutdown.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ register_shutdown_function(function() {
1010

1111
try {
1212
spawn(function() {
13-
echo "should not execute\n";
13+
echo "should execute\n";
1414
});
1515
echo "spawn succeeded\n";
1616
} catch (Async\AsyncException $e) {
@@ -33,5 +33,6 @@ start
3333
end
3434
normal spawn works
3535
shutdown handler start
36-
Error: Cannot spawn a coroutine when async is disabled
37-
shutdown handler end
36+
spawn succeeded
37+
shutdown handler end
38+
should execute

0 commit comments

Comments
 (0)