Potential sync optimizations for single-threaded schedulers
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
首先复现 Godbolt 示例,并阅读 issue 中提到的 sync_wait、async_scope 和 inline_scheduler 实现。跟踪 mutex 和条件变量是在何处引入的,以及那里是否能够获得 scheduler 类型信息。完成的标准是确定是否可以安全地移除单线程同步,并记录具体的实现方向,或者说明设计为何阻止这样做。
由索引模型根据 Issue 内容生成。
描述
I've been playing around with stdexec and had a thought about sync_wait and async_scope that I wanted to run by the community. I might be missing something obvious here, so please let me know if this doesn't make sense!
I noticed that when using sync_wait with inline_scheduler, we still use mutexes and condition variables internally, even though we know the work will run on the calling thread. Same thing seems to happen with async_scope when all tasks run on a single thread.
I was wondering:
- Is there a way (or maybe there already is?) to optimize away this synchronization overhead when we know at compile-time that everything will run on the same thread?
- Does the sender type system provide enough information to detect these cases?
Quick example of what made me think about this (godbolt):
#include <stdexec/execution.hpp>
#include <exec/inline_scheduler.hpp>
int main(int argc, char* argv[]) {
auto sdr = stdexec::schedule(exec::inline_scheduler{})
| stdexec::then([argc] { return argc; })
| stdexec::then([](auto n) { return 2 * n; });
auto [res] = stdexec::sync_wait(std::move(sdr)).value();
return res;
}
I expected the generated assembly to be equivalent, or extremely close, to simply writing:
int main(int argc, char* argv[]) {
auto then_f = [](auto n) { return 2 * n; };
auto [res] = std::optional{std::tuple{std::move(then_f)(argc)}}.value();
return res;
}
However, the generated code uses mutexes and condition variables.
I was thinking: could sync_wait potentially use type traits from the active scheduler to determine if it needs to be thread-safe? That way, it could avoid mutexes and condition variables in single-threaded cases.
The same could apply to async_scopes that run in single-threaded environments.
If my understanding of sync_wait and inline_scheduler is incorrect, please let me know!
Otherwise, it would be interesting to know whether such overhead is avoidable in single-threaded cases or if it's inherently tied to the design.
Thanks for any insights!
- 主要语言
- 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 天内回复