Skip to content

Commit 267e0f0

Browse files
committed
revert "Fix data race in async_scope"
1 parent d9abc71 commit 267e0f0

1 file changed

Lines changed: 2 additions & 15 deletions

File tree

include/exec/async_scope.hpp

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ namespace exec {
5151
inplace_stop_source __stop_source_{};
5252
mutable std::mutex __lock_{};
5353
mutable __std::atomic_ptrdiff_t __active_ = 0;
54-
mutable __std::atomic_ptrdiff_t __pending_notifiers_ =
5554
0; // Track in-flight __complete() calls
5655
mutable __intrusive_queue<&__task::__next_> __waiters_{};
5756

@@ -85,14 +84,8 @@ namespace exec {
8584
// the waiter is queued but after __active is checked, the waiter will never be notified
8685
std::unique_lock __guard{this->__scope_->__lock_};
8786
auto& __active = this->__scope_->__active_;
88-
auto& __pending = this->__scope_->__pending_notifiers_;
8987
auto& __waiters = this->__scope_->__waiters_;
90-
// Also check __pending_notifiers_ to avoid race with in-flight __complete() calls.
91-
// A __complete() that did fetch_sub but hasn't locked the mutex yet will have
92-
// incremented __pending_notifiers_, preventing us from completing immediately.
93-
if (
94-
__active.load(__std::memory_order_acquire) != 0
95-
|| __pending.load(__std::memory_order_acquire) != 0) {
88+
if (__active.load(__std::memory_order_acquire) != 0) {
9689
__waiters.push_back(this);
9790
return;
9891
}
@@ -165,13 +158,9 @@ namespace exec {
165158
__nest_op_base<_ReceiverId>* __op_;
166159

167160
static void __complete(const __impl* __scope) noexcept {
168-
// Increment pending BEFORE fetch_sub to close race window with on_empty().
169-
// This ensures on_empty() sees pending > 0 if we're about to lock the mutex.
170-
__scope->__pending_notifiers_.fetch_add(1, __std::memory_order_acquire);
171161
auto& __active = __scope->__active_;
162+
std::unique_lock __guard{__scope->__lock_};
172163
if (__active.fetch_sub(1, __std::memory_order_acq_rel) == 1) {
173-
std::unique_lock __guard{__scope->__lock_};
174-
__scope->__pending_notifiers_.fetch_sub(1, __std::memory_order_release);
175164
auto __local_waiters = std::move(__scope->__waiters_);
176165
__guard.unlock();
177166
__scope = nullptr;
@@ -181,8 +170,6 @@ namespace exec {
181170
__next->__notify_waiter(__next);
182171
// __scope must be considered deleted
183172
}
184-
} else {
185-
__scope->__pending_notifiers_.fetch_sub(1, __std::memory_order_release);
186173
}
187174
}
188175

0 commit comments

Comments
 (0)