Skip to content

Commit a8d163b

Browse files
authored
Merge pull request #73966 from rjmccall/condvar-await-scope
Fix a bug with task-to-thread continuations
2 parents aa61d95 + d3e7b51 commit a8d163b

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

stdlib/public/Concurrency/Task.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,7 +1442,8 @@ static void swift_continuation_awaitImpl(ContinuationAsyncContext *context) {
14421442
//
14431443
// This condition variable can be allocated on the stack of the blocking
14441444
// thread - with the address of it published to the resuming thread via the
1445-
// context.
1445+
// context. We do this in a new scope.
1446+
do {
14461447
ConditionVariable Cond;
14471448

14481449
context->Cond = &Cond;
@@ -1495,7 +1496,10 @@ static void swift_continuation_awaitImpl(ContinuationAsyncContext *context) {
14951496

14961497
#if SWIFT_CONCURRENCY_TASK_TO_THREAD_MODEL
14971498
// Since the condition variable is stack allocated, we don't need to do
1498-
// anything here to clean up
1499+
// anything here to clean up. But we do have to end the scope that we
1500+
// created the condition variable in so that it'll be destroyed before
1501+
// we try to tail-call.
1502+
} while (false);
14991503
#else
15001504
// Restore the running state of the task and resume it.
15011505
task->flagAsRunning();

0 commit comments

Comments
 (0)