kou commented on issue #39897:
URL: https://github.com/apache/arrow/issues/39897#issuecomment-1922660049

   Could you initialize S3 on the main thread explicitly?
   
   
   ```cpp
   #include <iostream>
   #include <thread>
   #include <arrow/api.h>
   #include <arrow/filesystem/api.h>
   
   void thread_main()
   {
       // Call FileSystemFromURI() and check the returned status code.
       std::string path;
       auto result = arrow::fs::FileSystemFromUri("s3://bucket/key", &path);
       if (result.ok()){
           std::cout << std::this_thread::get_id() << ": FileSystemFromUri() 
succeeded." << std::endl;
       } else {
           std::cout << std::this_thread::get_id() << ": FileSystemFromUri() 
failed." << std::endl;
       }
   }
   
   int main()
   {
      (void)arrow::fs::EnsureS3Initialized();
      const int num_threads = 2;
       auto threads = std::vector<std::thread>();
       for (int i = 0; i < num_threads; i++)
       {
           threads.push_back(std::thread(thread_main));
       }
   
       for (auto &thread : threads)
       {
           thread.join();
       }
   
       // This line would prevent a segfault if the above code were to work.
       (void)arrow::fs::FinalizeS3();
   }
   ```


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