kou commented on code in PR #40110:
URL: https://github.com/apache/arrow/pull/40110#discussion_r1496716577


##########
cpp/src/arrow/filesystem/s3fs.cc:
##########
@@ -2898,7 +2898,8 @@ struct AwsInstance {
     if (is_finalized_.load()) {
       return Status::Invalid("Attempt to initialize S3 after it has been 
finalized");
     }
-    if (!is_initialized_.exchange(true)) {
+    bool expected = false;
+    if (is_initialized_.compare_exchange_weak(expected, true)) {

Review Comment:
   Hmm. I think that the second `EnsureS3Initialized()` call should be blocked 
when the first `EnsureS3Initialized()` is running. If the second 
`EnsureS3Initialized()` call isn't blocked, following `FileSystemFromUri()` 
will be failed.
   
   Did you try a program provided in #39897?
   
   I think that we need to do something like:
   
   ```diff
   diff --git a/cpp/src/arrow/filesystem/s3fs.cc 
b/cpp/src/arrow/filesystem/s3fs.cc
   index a987d63a6d..f89b5bdabd 100644
   --- a/cpp/src/arrow/filesystem/s3fs.cc
   +++ b/cpp/src/arrow/filesystem/s3fs.cc
   @@ -3004,6 +3004,8 @@ Status InitializeS3(const S3GlobalOptions& options) {
    }
    
    Status EnsureS3Initialized() {
   +  static std::mutex mutex;
   +  std::lock_guard<std::mutex> lock(mutex);
      return EnsureAwsInstanceInitialized(S3GlobalOptions::Defaults()).status();
    }
   ```



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