-
Notifications
You must be signed in to change notification settings - Fork 845
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One suggestion made.
#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); | ||
} | ||
|
There was a problem hiding this comment.
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);
}
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* fix non thread safe check in VarianceDataForLabel::addRgroupData() * scope mutex
Another detection flagged by the thread sanitizer.
In this case, there's a data race condition in
rgroupData->fingerprint
, which is updated insideaddFingerprintToRGroupData()
. 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.