Skip to content
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

Fix duplicate non thread safe check in VarianceDataForLabel #5212

Merged
merged 2 commits into from
May 2, 2022

Conversation

ricrogz
Copy link
Contributor

@ricrogz ricrogz commented Apr 17, 2022

Another detection flagged by the thread sanitizer.

In this case, there's a data race condition in rgroupData->fingerprint, which is updated inside addFingerprintToRGroupData(). Maybe not a big issue due to the duplicated check, but it's still good to get it fixed by removing the duplicate check outside the mutex.

Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

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

One suggestion made.

Comment on lines 241 to 247
#ifdef RDK_THREADSAFE_SSS
const std::lock_guard<std::mutex> lock(groupMutex);
const std::lock_guard<std::mutex> lock(groupMutex);
#endif
if (rgroupData->fingerprint == nullptr) {
addFingerprintToRGroupData(rgroupData);
}
if (rgroupData->fingerprint == nullptr) {
addFingerprintToRGroupData(rgroupData);
}

Copy link
Member

Choose a reason for hiding this comment

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

I think this leaves the mutex alive longer than it needs to be.
You can reproduce the original lifetime of the mutex by introducing a local scope:

{
#ifdef RDK_THREADSAFE_SSS
  const std::lock_guard<std::mutex> lock(groupMutex);
#endif
  if (rgroupData->fingerprint == nullptr) {
    addFingerprintToRGroupData(rgroupData);
  }
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, done

@greglandrum greglandrum added bug Cleanup Code cleanup and refactoring labels May 2, 2022
@greglandrum greglandrum added this to the 2022_03_3 milestone May 2, 2022
Copy link
Member

@greglandrum greglandrum left a comment

Choose a reason for hiding this comment

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

LGTM

@greglandrum greglandrum merged commit 173a968 into rdkit:master May 2, 2022
@ricrogz ricrogz deleted the fix_RgroupDecomp_check branch May 2, 2022 12:42
greglandrum pushed a commit that referenced this pull request Jun 2, 2022
* fix non thread safe check in VarianceDataForLabel::addRgroupData()

* scope mutex
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Cleanup Code cleanup and refactoring
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants