westonpace commented on a change in pull request #9892:
URL: https://github.com/apache/arrow/pull/9892#discussion_r609655564
##########
File path: cpp/src/arrow/util/thread_pool.h
##########
@@ -233,15 +233,7 @@ class ARROW_EXPORT SerialExecutor : public Executor {
if (final_fut.is_finished()) {
return final_fut.result();
}
- final_fut = final_fut.Then(
- [this](const T& res) {
- MarkFinished();
- return res;
- },
- [this](const Status& st) -> Result<T> {
- MarkFinished();
- return st;
- });
+ final_fut.AddCallback([this](const Result<T>&) { MarkFinished(); });
Review comment:
There are some differences between `AddCallback` and `Then` here.
Callbacks are run after the future waiters are notified. This means that
`final_fut.result()` would return before `MarkFinished()` has run. It
"shouldn't" matter since it would probably be bad form to mark the final future
complete while there are other tasks lying around on the executor. However, I
wasn't sure it would always be safe. For example, whomever called
`MarkFinished` is going to destruct themselves and it might be nice to ensure
that happens before we return from `result()`.
On the other hand, by using `Then` we ensure that `MarkFinished()` has
completed executing before `final_fut.result()` returns.
So I'm not certain this change is a problem but I feel it does add risk that
we don't need.
--
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:
[email protected]