westonpace commented on a change in pull request #9892: URL: https://github.com/apache/arrow/pull/9892#discussion_r608244115
########## File path: cpp/src/arrow/util/thread_pool.h ########## @@ -189,6 +190,64 @@ class ARROW_EXPORT Executor { StopCallback&&) = 0; }; +/// \brief An executor implementation that runs all tasks on a single thread using an +/// event loop. +/// +/// Note: Any sort of nested parallelism will deadlock this executor. Blocking waits are +/// fine but if one task needs to wait for another task it must be expressed as an +/// asynchronous continuation. +class ARROW_EXPORT SerialExecutor : public Executor { + public: + template <typename T = ::arrow::detail::Empty> + using FinishSignal = internal::FnOnce<void(const Result<T>&)>; + template <typename T = ::arrow::detail::Empty> + using Scheduler = internal::FnOnce<Status(Executor*, FinishSignal<T>)>; + + SerialExecutor(); + ~SerialExecutor(); + + int GetCapacity() override { return 1; }; + Status SpawnReal(TaskHints hints, FnOnce<void()> task, StopToken, + StopCallback&&) override; + + /// \brief Runs the scheduler and any scheduled tasks + /// + /// The scheduler must either return an invalid status or call the finish signal. + /// Failure to do this will result in a deadlock. For this reason it is preferable (if + /// possible) to use the helper methods (below) RunSynchronously/RunSerially which + /// delegates the responsiblity onto a Future producer's existing responsibility to + /// always mark a future finished (which can someday be aided by ARROW-12207). + template <typename T> + static Result<T> RunInSerialExecutor(Scheduler<T> initial_task) { + auto serial_executor = std::make_shared<SerialExecutor>(); Review comment: Fixed. -- 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