Skip to content

Commit

Permalink
Fix race condition that would make the system context tests fail occa…
Browse files Browse the repository at this point in the history
…sionally.
  • Loading branch information
lucteo committed Aug 14, 2024
1 parent a235244 commit 3570ff7
Showing 1 changed file with 12 additions and 6 deletions.
18 changes: 12 additions & 6 deletions include/exec/__detail/__system_context_default_impl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,20 +45,26 @@ namespace exec::__system_context_default_impl {

void set_value() noexcept {
auto __op = __op_;
__r_->set_value();
__op->__destruct();
auto __r = __r_;
__op->__destruct(); // destroys the operation, including `this`.
__r->set_value();
// Note: when calling a completion signal, the parent operation might complete, making the
// static storage passed to this operation invalid. Thus, we need to ensure that we are not
// using the operation state after the completion signal.
}

void set_error(std::exception_ptr __ptr) noexcept {
auto __op = __op_;
__r_->set_error(__ptr);
__op->__destruct();
auto __r = __r_;
__op->__destruct(); // destroys the operation, including `this`.
__r->set_error(__ptr);
}

void set_stopped() noexcept {
auto __op = __op_;
__r_->set_stopped();
__op->__destruct();
auto __r = __r_;
__op->__destruct(); // destroys the operation, including `this`.
__r->set_stopped();
}
};

Expand Down

0 comments on commit 3570ff7

Please sign in to comment.