Assert on: ctx->remote_ready_is_linked() on cond_var.wait_for(..)

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

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

評価

難易度
4/5
見積もり時間
3〜5日
初心者へのやさしさ
28/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
cpp

調査の方向性

scheduler::sleep2ready_() から開始して cond_var.wait_for() の経路を追跡し、cond_var.wait() と比較します。特に、タイマーによるウェイクアップとスレッド間の notify_all() が remote-ready リンクにどのような影響を与えるかを確認します。Boost 1.69、shared_work、外部の round_robin スレッド、アサーション有効の状態でアサーションを再現します。報告されたシナリオがアサーションに違反しなくなるか、その期待される動作が文書化されれば完了です。

索引モデルが issue の本文から書いたものです。

説明

Situation:
0. I use boost 1.69

  1. Have one thread pool (TP) with shared_work algo started on it.
  2. fibers running in TP is waiting on cond_var:
	boost::fibers::mutex _mtx;
	boost::fibers::condition_variable _condition;
...


	std::unique_lock lock{ _mtx };
	if (!_condition.wait_for(lock, WaitTimeout(), GetWaitPredicate()))
		throw std::runtime_error{ __FUNCTION__": pontentially lost" };

  1. I Have other threads (not in thread pool, round_robin default scheduler). Where I notify cv:
	std::unique_lock lock{ _mtx };
	// fullfill predicate somehow:
	_condition.notify_all();

If I build the program with assertions I got very fast the assert:

void
scheduler::sleep2ready_() noexcept {
    // move context which the deadline has reached
    // to ready-queue
    // sleep-queue is sorted (ascending)
    std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();
    sleep_queue_type::iterator e = sleep_queue_.end();
    for ( sleep_queue_type::iterator i = sleep_queue_.begin(); i != e;) {
        context * ctx = & ( * i);
        // dipatcher context must never be pushed to sleep-queue
        BOOST_ASSERT( ! ctx->is_context( type::dispatcher_context) );
        BOOST_ASSERT( main_ctx_ == ctx || ctx->worker_is_linked() );
        BOOST_ASSERT( ! ctx->ready_is_linked() );
#if ! defined(BOOST_FIBERS_NO_ATOMICS)
        BOOST_ASSERT( ! ctx->remote_ready_is_linked() );   <---- THIS ASSERT
#endif
...

As far As I understand the fiber can be waked up by timer or by notification from another thread and this is not allowed by this assert. How can I fix the issue?

P.S. When I changed wait_for() -> wait() the assert is gone!

Thanks!

主要言語
C++
スター
512
フォーク
124
PR マージ指標
30日以内にマージされた PR はありません

環境構築

このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。

はじめの一歩

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

boostorg/fiber のほかの issue

boostorg/fiber の issue をすべて見る

似ている issue

C++ の issue をもっと見る

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

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