Annotate folly::SharedMutex with TSAN annotations
Summary: This diff adds TSAN annotations to `folly::SharedMutex` to allow TSAN to find lock inversions with this type of mutex. Note that only the WritePriority version is annotated, and the ReadPriority version is not. See the comments in the source code for an explanation of this. Some notes about how the annotation was done: - We always call the RELEASED annotations at the beginning of unlock(), and the ACQUIRED annotations at the end of lock(). This prevents a double locking interleaving where thread 1 has unlocked it and before RELEASED is called, another thread has locked it and calls ACQUIRED first. - These annotations treat upgrade locks as equivalent to a shared lock. This prevents any false positives, and keeps the annotations simple. - We need to keep the constructor for SharedMutex as `constexpr` to avoid static initialization bugs. As a result, we need to lazily annotate creation of the mutex. To do this, this adds an extra bit to the `SharedMutex` state to keep track if initialization has been called. In TSAN builds, we have an array of mutexes to enforce that initialization is called at most once. - This diff introduces a new template param AnnotateForThreadSanitizer (default is False). This allows users to use a new folly::SharedMutexSuppressTSAN version to avoid lock inversion detection if there are noisy lock inversions. However, this should be the exception and not the norm. In normal build modes, this is equivalent to a normal SharedMutex. Reviewed By: nbronson Differential Revision: D9677058 fbshipit-source-id: b0f5719a75024937fb81672435fb1c9802f255d7
Showing
This diff is collapsed.
Please register or sign in to comment