Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Potential sync optimizations for single-threaded schedulers

オープン
#1,471 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
機能追加
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cpp
領域
backend

調査の方向性

まず Godbolt の例を再現し、issue で言及されている sync_wait、async_scope、inline_scheduler の実装を読みます。mutex と condition variable がどこで導入されているか、またその箇所で 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:

  1. 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?
  2. 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日 17時間
マージ済み PR(30日)
37

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

NVIDIA/stdexec のほかの issue

NVIDIA/stdexec の issue をすべて見る

似ている issue

C++ の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。