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

Avoid async scope lockup

Đang mở
#1,909 5 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

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

Hướng nghiên cứu

Bắt đầu từ reproducer async_scope, test2 và test3 được cung cấp, đồng thời so sánh ba trường hợp scheduling trong khi theo dõi việc hủy và quá trình hoàn tất scope. Tái hiện assertion của destructor, xác định lý do các trường hợp 2 và 3 vẫn chưa hoàn tất sau request_stop(), và xác minh rằng hành vi hủy dự kiến hoàn tất mà không có assertion.

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

Mô tả

exec::task<void> test(asio::io_context &ioContext)
{
    asio::steady_timer timer(ioContext);
    timer.expires_after(std::chrono::seconds(10));
    auto [error] = co_await timer.async_wait(asio::as_tuple(exec::asio::use_sender));
}

exec::task<void> test2(exec::async_scope& scope, asio::io_context &ioContext)
{
#if 1
    co_await exec::reschedule_coroutine_on(stdexec::inline_scheduler{});
    co_await scope.nest(test(ioContext));
#elif 0
    co_await stdexec::on(stdexec::inline_scheduler{}, scope.nest(test(ioContext)));
#elif 0
    co_await scope.nest(stdexec::on(stdexec::inline_scheduler{}, test(ioContext)));
#endif
}

exec::task<void> test3(exec::async_scope& scope, asio::io_context &ioContext)
{
    co_await test2(scope, ioContext);
}

    asio::io_context ioContext;
    MyThread recvThread;
    std::optional<exec::async_scope> asyncScope;
    asyncScope.emplace();
    exec::static_thread_pool ctx{1};

    asio::executor_work_guard<asio::io_context::executor_type> workGuard(
        asio::make_work_guard(ioContext));

    recvThread.start([&]
        {
            ioContext.run();
            printf("test\n");
        }, "client_network_thread");


    exec::start_detached(stdexec::starts_on(MainThreadScheduler(), test3(*asyncScope, ioContext)));
    Scheduler::getSingleton()->run(GetTicks());

    sleep(5);
    workGuard.reset();

    asyncScope->request_stop();
    recvThread.join();
    asyncScope.emplace();

What I am attempting to do is to wrap an async function in an async scope t make it cancellable.
In this example the MainThreadScheduler only schedules one initial time so it is expected that it will never fully finish the test3 task.

However I would still like to successfully cancel it. In the test2 function the first case works as expected. Both case 2 and 3 assert inside the asyncScope destructor since the work isn't considered finished. It wasn't fully clear to me why the work isn't considered finished in these cases. Especially in case 2.

Ngôn ngữ chính
C++
Star
2.4k
Fork
270
Merge trung bình
2 ngày 17 giờ
Pull request đã merge (30 ngày)
37

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

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.