Make TSAN aware of unlock_shared() called on a different thread in ObserverManager
Summary: `folly::SharedMutex` allows `unlock_shared()` to be called in a different thread from the one that locked it There are some places in folly that use this property. Example: In `ObserverManager`, the calling thread 1. acquires the read lock 2. then it schedules some async work and gives ownership of the lock guard to the lambda 3. the thread that performs the async work will unlock the mutex However, this causes false positives for TSAN. It looks like this breaks TSAN's assumptions that a read-write mutex is always read locked and unlocked in the same thread. In the example above, TSAN thinks the calling thread in step (1) still owns the mutex, even though semantically the mutex is now owned by the thread in step (3). This results in false positives for running unit tests with an annotated version of `folly::SharedMutex`. TSAN reports a lock inversion between the `folly::Singleton vaule_.state_` mutex, and the read lock referenced in `ObserverManager`. To suppress this error, this change annotates ObserverManager to let TSAN know that the the thread in step 1 has dropped the lock, and the thread in step 3 now owns the lock. Reviewed By: andriigrynenko Differential Revision: D9797937 fbshipit-source-id: c0e5277bb9cb2f404df8abd3c3d6ea4a16460c78
Showing
Please register or sign in to comment