lidavidm commented on a change in pull request #9941: URL: https://github.com/apache/arrow/pull/9941#discussion_r609073856
########## File path: cpp/src/arrow/util/async_generator.h ########## @@ -1195,25 +1199,48 @@ class BackgroundGenerator { ClearQueue(); queue.push(spawn_status); } + task_finished.MarkFinished(); } } } internal::Executor* io_executor; Iterator<T> it; + bool started; bool running; bool finished; + bool should_shutdown; int max_q; int q_restart; std::queue<Result<T>> queue; util::optional<Future<T>> waiting_future; util::Mutex mutex; + Future<> task_finished; + }; + + struct Cleanup { + explicit Cleanup(State* state) : state(state) {} + ~Cleanup() { + Future<> finish_fut; + { + auto lock = state->mutex.Lock(); + if (!state->started) { Review comment: I think we need only `state->running` since that also covers the case that the background task is not currently running, but has run in the past (which this check misses). -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org