Skip to content

[C++] Potential bug in ReadaheadGenerator #45953

@mapleFU

Description

@mapleFU
          I think below might be a incorrect ordering:

Thread1: check state_->finished.load() == true in 1
Thread2: state->MarkFinishedIfDone, state->final_future.MarkFinished
Thread1: state_->num_running.fetch_add(1) in 2
Thread1: state->final_future.MarkFinished

    auto result = std::move(state_->readahead_queue.front());
    state_->readahead_queue.pop();
    if (state_->finished.load()) { // 1
      state_->readahead_queue.push(AsyncGeneratorEnd<T>());
    } else {
      state_->num_running.fetch_add(1); // 2
      auto back_of_queue = state_->source_generator();
      auto back_of_queue_after_check =
          AddMarkFinishedContinuation(std::move(back_of_queue));
      state_->readahead_queue.push(std::move(back_of_queue_after_check));
    }

Originally posted by @mapleFU in #44990 (comment)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions