Skip to content

Commit 4f740a4

Browse files
committed
Concurrency: support draining the main queue in single threaded mode
When built in single threaded mode, the runtime does not use dispatch to queue the tasks. As a result, pumping the dispatch main queue will simply wait indefinitely. In the single threaded mode, simply halt execution and drain all pending tasks before returning. This allows forward progress in the single threaded mode.
1 parent f205b20 commit 4f740a4

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,12 @@ void swift::swift_continuation_logFailedCheck(const char *message) {
536536
}
537537

538538
void swift::swift_task_asyncMainDrainQueue() {
539+
#if SWIFT_CONCURRENCY_COOPERATIVE_GLOBAL_EXECUTOR
540+
bool Finished = false;
541+
donateThreadToGlobalExecutorUntil([](void *context) {
542+
return *reinterpret_cast<bool*>(context);
543+
}, &Finished);
544+
#else
539545
#if defined(_WIN32)
540546
static void(FAR *pfndispatch_main)(void) = NULL;
541547

@@ -561,4 +567,5 @@ void swift::swift_task_asyncMainDrainQueue() {
561567
else
562568
dispatch_main();
563569
#endif
570+
#endif
564571
}

0 commit comments

Comments
 (0)