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

Aperta
#259 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
28/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
cpp

Direzione di ricerca

Parti da scheduler::sleep2ready_() e segui il percorso di cond_var.wait_for(), confrontandolo con cond_var.wait(), in particolare il modo in cui i risvegli del timer e notify_all() tra thread influiscono sui collegamenti remote-ready. Riproduci l’asserzione con Boost 1.69, shared_work, un thread round_robin esterno e le asserzioni abilitate; il lavoro è concluso quando lo scenario segnalato non viola più l’asserzione oppure il suo comportamento previsto è documentato.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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!

Lingua principale
C++
Stelle
512
Fork
124
Merge medio
23g 19h
PR unite (30g)
1

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di boostorg/fiber

Tutte le issue di boostorg/fiber

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.