Skip to content

Conversation

@AliRana30
Copy link

@AliRana30 AliRana30 commented Jan 30, 2026

Rationale for this change

DictionaryArray::dictionary() does lazy initialization without thread synchronization, causing race conditions when multiple threads access the same instance concurrently.

Chages

  • Use std::call_once with std::once_flag for thread-safe lazy initialization
  • Added #include <mutex>
  • Removed TODO comment at line 112

The dictionary() method was doing lazy initialization without thread
safety, causing potential race conditions when multiple threads access
the same DictionaryArray instance. This could lead to memory corruption
or double-free errors.

Fixed by using std::call_once with std::once_flag to ensure the
dictionary is initialized exactly once in a thread-safe manner.

Closes apache#49064
@github-actions
Copy link

⚠️ GitHub issue #49064 has been automatically assigned in GitHub to PR creator.

@HyukjinKwon
Copy link
Member

Oh actually I think this is a duplicate of #48905 :-).

@AliRana30
Copy link
Author

Thanks for catching that! You're right, this is a duplicate of #48905. Should I:

  1. Close this PR and the issue Thread Safety Bug in DictionaryArray::dictionary() #49064 as duplicate?
  2. Or update this PR to reference both issues (GH-36503: [C++] Make DictionaryArray::dictionary() thread-safe #48905, Thread Safety Bug in DictionaryArray::dictionary() #49064)?

Let me know!

@HyukjinKwon
Copy link
Member

I think you can close the issue as there is already one. For the PR, I am not the committer in this repo so I leave it to others 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants