paleolimbot commented on code in PR #12558:
URL: https://github.com/apache/arrow/pull/12558#discussion_r843910759


##########
r/R/arrow-package.R:
##########
@@ -31,6 +31,11 @@
 
 #' @importFrom vctrs s3_register vec_size vec_cast vec_unique
 .onLoad <- function(...) {
+  if (arrow_available()) {
+    # Make sure C++ knows on which thread it is safe to call the R API
+    InitializeMainRThread()

Review Comment:
   I asked in the r-lib slack channel and nobody seems to feel that this will 
be a problem. They did advise to check `parallel::mclapply()` since this 
creates a fork of the process, but a check seems to indicate that the value of 
`std::this_thread::get_id()` seems to be stable if somebody does happen to do 
that:
   
   ``` r
   cpp11::cpp_source(code = '
   #include "cpp11.hpp"
   #include <thread>
   #include <sstream>
   
   [[cpp11::register]]
   std::string thread_id() {
     std::thread::id id = std::this_thread::get_id();
     std::stringstream ss;
     ss << id;
     return ss.str();
   }
   ')
   
   thread_id()
   #> [1] "0x100e33d40"
   unique(lapply(1:1e3, function(x) thread_id()))
   #> [[1]]
   #> [1] "0x100e33d40"
   unique(parallel::mclapply(1:1e3, function(x) thread_id(), mc.cores = 8))
   #> [[1]]
   #> [1] "0x100e33d40"
   ```



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