Skip to content

[ORC] Fix synchronization in CoreAPIsTest. #144556

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vtjnash
Copy link
Member

@vtjnash vtjnash commented Jun 17, 2025

The code previously appeared to have a (benign?) race condition on WorkThreads.size, since it was being accessed outside of the mutex lock that protected it on the threads. This is usually okay since 1a1d6e6, but doesn't seem reliable in general, so fix this code to express the intent more accurately. This instead relies on the same general principles as ref-counting, where each existing reference (thread) can add new references (threads) because they already have a reference themselves (until joined).

The code previously appeared to have a (benign?) race condition on
`WorkThreads.size`, since it was being accessed outside of the mutex
lock that protected it on the threads. This is usually okay since
1a1d6e6, but doesn't seem reliable in
general, so fix this code to express the intent more accurately. This
relies on the same general principles as ref-counting, where each
existing reference (thread) can add new references (threads) because
they already have a reference themselves (until joined).
@vtjnash vtjnash requested a review from lhames June 17, 2025 16:08
Copy link

github-actions bot commented Jun 17, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@lhames lhames left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Otherwise LGTM. Thanks very much for spotting this bug!

std::vector<std::thread> WorkThreads;
SmallVector<std::thread,0> WorkThreads;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this change in vector type necessary? If not it'd be better to leave out.

Comment on lines -1565 to +1564
std::lock_guard<std::mutex> Lock(WorkThreadsMutex);
std::unique_lock Lock(WorkThreadsMutex);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this could remain a lock_guard, since manual locking/unlocking isn't needed here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants