westonpace commented on a change in pull request #9644:
URL: https://github.com/apache/arrow/pull/9644#discussion_r597951679



##########
File path: cpp/src/arrow/util/thread_pool.h
##########
@@ -102,16 +102,34 @@ class ARROW_EXPORT Executor {
   // CPU heavy work off the I/O thread pool.  So the I/O task should transfer
   // the future to the CPU executor before returning.
   template <typename T>
-  Future<T> Transfer(Future<T> future) {
+  Future<T> Transfer(Future<T> future, bool force_spawn = false) {
     auto transferred = Future<T>::Make();
-    future.AddCallback([this, transferred](const Result<T>& result) mutable {
+    auto callback = [this, transferred](const Result<T>& result) mutable {
       auto spawn_status = Spawn([transferred, result]() mutable {
         transferred.MarkFinished(std::move(result));
       });
       if (!spawn_status.ok()) {
         transferred.MarkFinished(spawn_status);
       }
-    });
+    };
+    auto callback_factory = [&callback]() { return callback; };
+    auto callback_added = future.TryAddCallback(callback_factory);
+    if (!callback_added) {
+      if (force_spawn) {
+        auto spawn_status = Spawn([future, transferred]() mutable {
+          transferred.MarkFinished(future.result());
+        });
+        if (!spawn_status.ok()) {
+          transferred.MarkFinished(spawn_status);
+        }
+        return transferred;

Review comment:
       Haha, it made sense in my head but you're right, this isn't the right 
approach.  I'm confused as to how it worked but I guess it helped inject a 
little bit of opportunity in the system because it would take a little while 
for the spwaned thread to mark the callback finished so it slowed it down a 
little.  Ok, I'm going to try something different.




-- 
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


Reply via email to