How implement a coroutine suspend-running in a multi-thread trampoline scheduler when using a custom sender?
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 25/100
- Issue 类型
- 功能
- 描述清晰度
- 需要澄清
- 活跃度
- 停滞
- 技术栈
- cpp
调研方向
该 issue 仅提供了一个 inline counter_sender 示例,并提到了 trampoline_scheduler、schedule()、then()、connect() 和 sync_wait();首先检查这些 API 及其 operation-state 生命周期规则。一种有用的解决方案应定义一种受支持的方式,使正在运行的 coroutine 能够跨越多线程 trampoline 暂停和恢复,并通过一个具有明确完成行为的可运行示例版本加以演示。
由索引模型根据 Issue 内容生成。
描述
Something like this
#include <unifex/single_thread_context.hpp>
#include <unifex/trampoline_scheduler.hpp>
#include <unifex/let_value.hpp>
#include <unifex/just.hpp>
#include <unifex/sync_wait.hpp>
#include <unifex/then.hpp>
using namespace unifex;
class counter_sender {
public:
counter_sender(int start, int end, trampoline_scheduler& scheduler)
: current_(start), end_(end), scheduler_(scheduler) {}
template<typename Receiver>
struct operation {
operation(int current, int end,
trampoline_scheduler& scheduler, Receiver&& receiver)
: current_(current)
, end_(end)
, scheduler_(scheduler)
, receiver_((Receiver&&)receiver) {}
void start() noexcept {
if (current_ >= end_) {
unifex::set_value(std::move(receiver_), current_);
return;
}
auto next = current_ + 1;
auto reschedule =
scheduler_.schedule() |
then([this, next]() {
auto new_op = operation{
next,
end_,
scheduler_,
(Receiver&&)receiver_
};
new_op.start();
});
// restart
connect(std::move(reschedule), receiver_).start();
}
private:
int current_;
int end_;
trampoline_scheduler& scheduler_;
Receiver receiver_;
};
template<typename Receiver>
auto connect(Receiver&& receiver) {
return operation<Receiver>{
current_, end_, scheduler_, (Receiver&&)receiver
};
}
private:
int current_;
int end_;
trampoline_scheduler& scheduler_;
};
void example() {
trampoline_scheduler scheduler{};
auto result = sync_wait(counter_sender{1, 5, scheduler});
if (result) {
std::cout << "Final count: " << *result << "\n";
}
}
- 主要语言
- C++
- 星标
- 2.4k
- 派生
- 270
- 平均合并
- 2 天 10 小时
- 30 天内合并 PR
- 42
环境准备
我们还没有检查这个项目的环境配置文件。先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
NVIDIA/stdexec 的其他 Issue
-
inline_scheduler's namespace-scope static_assert fails under nvcc (private nested __sender access)未关闭
难度 2/5 1-3 小时 新手友好度 65/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 45/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 48/100
维护者通常 1 天内回复
-
难度 4/5 3-5 天 新手友好度 65/100
维护者通常 1 天内回复
相似的 Issue
-
category:port-update
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复
-
难度 1/5 1-3 小时 新手友好度 88/100
tensorflow/tflite-micro#3784 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 88/100
维护者通常 1 天内回复
-
agentic-workflows automation
难度 2/5 1-3 小时 新手友好度 78/100
tenstorrent/tt-metal#57946 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
aristocratos/btop#1857 ·
维护者通常 3 天内回复