frreiss commented on issue #39897:
URL: https://github.com/apache/arrow/issues/39897#issuecomment-1924909629
Yes, making a call to ``EnsureS3Initialized()`` prior to launching any
background threads makes the example work.
It looks like I call call that function from inside the worker threads while
holding a mutex and get the same effect:
```c++
#include <iostream>
#include <thread>
#include <arrow/api.h>
#include <arrow/filesystem/api.h>
std::mutex s3_init_mutex;
arrow::Status thread_main()
{
{
std::lock_guard<std::mutex> guard(s3_init_mutex);
ARROW_RETURN_NOT_OK(arrow::fs::EnsureS3Initialized());
}
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;
}
return result.status();
}
int main()
{
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();
}
```
Perhaps ``FileSystemFromUriReal()`` should acquire a mutex while calling
``EnsureS3Initialized()``?
--
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]