File tree Expand file tree Collapse file tree 1 file changed +10
-0
lines changed
stdlib/public/Concurrency Expand file tree Collapse file tree 1 file changed +10
-0
lines changed Original file line number Diff line number Diff line change @@ -438,6 +438,11 @@ static void completeTaskImpl(AsyncTask *task,
438
438
SwiftError *error) {
439
439
assert (task && " completing task, but there is no active task registered" );
440
440
441
+ // This release-fence synchronizes with the acquire-fences performed
442
+ // by any tasks that resume after awaiting a task's completion. It ensures
443
+ // non-atomic writes done by this task are observable by those tasks.
444
+ std::atomic_thread_fence (std::memory_order_release);
445
+
441
446
// Store the error result.
442
447
auto asyncContextPrefix = reinterpret_cast <AsyncContextPrefix *>(
443
448
reinterpret_cast <char *>(context) - sizeof (AsyncContextPrefix));
@@ -540,6 +545,8 @@ static void future_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
540
545
541
546
SWIFT_CC (swiftasync)
542
547
static void task_wait_throwing_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
548
+ // This acquire synchronizes with the release in `completeTaskImpl`.
549
+ std::atomic_thread_fence (std::memory_order_acquire);
543
550
544
551
auto context = static_cast <TaskFutureWaitAsyncContext *>(_context);
545
552
auto resumeWithError =
@@ -550,6 +557,9 @@ static void task_wait_throwing_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *
550
557
SWIFT_CC (swiftasync)
551
558
static void
552
559
task_future_wait_resume_adapter(SWIFT_ASYNC_CONTEXT AsyncContext *_context) {
560
+ // This acquire synchronizes with the release in `completeTaskImpl`.
561
+ std::atomic_thread_fence (std::memory_order_acquire);
562
+
553
563
return _context->ResumeParent (_context->Parent );
554
564
}
555
565
You can’t perform that action at this time.
0 commit comments