-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 race conditions in shard #4188
Conversation
ThreadSafetyAnalysis was used to identify race conditions in this file. This analysis was modivated by a (rare) crash while running unit tests. Add locks to Shard flagged by ThreadSafetyAnalysis
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 ran the failing unit test in a loop 10525 times with no seg faults. I think this particular race condition is fixed. Thanks for taking care of this!
@@ -316,29 +318,30 @@ class Shard final | |||
boost::filesystem::path const dir_; | |||
|
|||
// Storage space utilized by the shard | |||
std::uint64_t fileSz_{0}; | |||
GUARDED_BY(mutex_) std::uint64_t fileSz_{0}; |
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 really like this annotation! Could not be clearer.
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.
As a side note: one down side to these annotations being bolted-on and not part of the language is we usually put the annotations at the end of a declaration, but when the variable is initialized, we need to put it at the beginning. That's unfortunate, but not a killer.
@undertome, has @seelabs addressed your concerns? |
yes |
High Level Overview of Change
This PR introduces two changes:
ThreadSafetyAnalysis
To compile with
ThreadSafetyAnalysis
, compile with clang and use-Dthread_safety_analysis=On
with cmake. Note: this will compile with clang's standard library and may not link. This is OK, we are running this for the compile warnings, not for the executable.This would be a good PR to discuss objections to the annotations required by
ThreadSafetyAnalysis
Type of Change