pitrou commented on code in PR #13635:
URL: https://github.com/apache/arrow/pull/13635#discussion_r981246676


##########
r/src/safe-call-into-r-impl.cpp:
##########
@@ -42,43 +57,40 @@ bool CanRunWithCapturedR() {
 std::string TestSafeCallIntoR(cpp11::function r_fun_that_returns_a_string,
                               std::string opt) {
   if (opt == "async_with_executor") {
-    std::thread* thread_ptr;
+    std::unique_ptr<std::thread> thread_ptr;
 
     auto result =
         RunWithCapturedR<std::string>([&thread_ptr, 
r_fun_that_returns_a_string]() {
           auto fut = arrow::Future<std::string>::Make();
-          thread_ptr = new std::thread([fut, r_fun_that_returns_a_string]() 
mutable {
-            auto result = SafeCallIntoR<std::string>([&] {
-              return cpp11::as_cpp<std::string>(r_fun_that_returns_a_string());
-            });
+          thread_ptr =
+              std::make_unique<std::thread>([&fut, 
r_fun_that_returns_a_string]() {
+                auto result = SafeCallIntoR<std::string>([&] {
+                  return 
cpp11::as_cpp<std::string>(r_fun_that_returns_a_string());
+                });
 
-            fut.MarkFinished(result);
-          });
+                fut.MarkFinished(result);
+              });
 
           return fut;
         });
 
     thread_ptr->join();

Review Comment:
   Do you want to check that the thread is initialized before trying to join it?
   (better than a hard crash)



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

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to