Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

`stop-when`: the fused token's callback can run twice, or be skipped, when the first token is already stopped

Đã đóng
#2,326 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@workingBanana đang làm issue này rồi.

Từ ngày 12/10/2026.

  • #2327 của @workingBanana — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
backend-api-design

Hướng nghiên cứu

The issue identifies __stop_when_::__fused_token<T1, T2>::callback_type and gives a reproducer using stdexec/execution.hpp. Read the callback member declarations and constructor initialization order, then run the reproducer to check immediate invocation when the first token is already stopped. Done means the callback runs once at registration and is not called again when the second token stops. Pull request #2327 is already open against this issue.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

Summary

__stop_when_::__fused_token<T1, T2>::callback_type declares its once-flag __called_ after the two inner callbacks:

_Fn                 __fn_;
__cb1_t             __cb1_;
__cb2_t             __cb2_;
__std::atomic<bool> __called_{false};   // initialized last

If the first token is already stopped, __cb1_'s constructor invokes the callback immediately. That callback does __called_.exchange(true) on an object whose lifetime hasn't started yet. Then __called_'s initializer stores false. So the result depends on the indeterminate value:

  • if it was 0: the function runs at registration, the flag is reset, and the function runs a second time when the second token is stopped;
  • if it was non-zero: the function is skipped at registration. It runs only if the second token is stopped later, and is lost otherwise.

Both violate [exec.stop.when]: the callback must be invoked when either token is stopped, and at most once.

Introduced in https://github.com/NVIDIA/stdexec/pull/2234

Reproducer

#include <stdexec/execution.hpp>
#include <cstdio>

namespace ex = STDEXEC;

int main() {
  ex::inplace_stop_source a, b;
  a.request_stop(); // the sender's token is already stopped
  int calls = 0, at_registration = -1;
  auto probe = ex::read_env(ex::get_stop_token) | ex::then([&](auto token) {
    auto fn = [&]() noexcept { ++calls; };
    ex::stop_callback_for_t<decltype(token), decltype(fn)> cb(token, fn); // must run: a is stopped
    at_registration = calls;
    b.request_stop(); // must not run again
  });
  // The inner stop-when sees a stoppable receiver token (b), so its child gets a fused token.
  ex::sync_wait(ex::__stop_when(ex::__stop_when(probe, a.get_token()), b.get_token()));
  std::printf("calls at registration: %d (expected 1), in total: %d (expected 1)\n",
              at_registration, calls);
  return at_registration == 1 && calls == 1 ? 0 : 1;
}

Then output will be: calls at registration: 1 (expected 1), in total: 2 (expected 1). It should be 1 and 1.

Ngôn ngữ chính
C++
Star
2.5k
Fork
276
Merge trung bình
1 ngày 16 giờ
Pull request đã merge (30 ngày)
65

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của NVIDIA/stdexec

Tất cả issue của NVIDIA/stdexec

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.