sync: document RWMutex race semantics

RWMutex provides explicit acquire/release synchronization events to the
race detector to model the mutex. It disables sync events within the
methods to avoid e.g., the atomics from adding false synchronization
events, which could cause false negatives in the race detector.

Change-Id: I5126ce2efaab151811ac264864aab1fa025a4aaf
Run-TryBot: Michael Pratt <>
TryBot-Result: Go Bot <>
Reviewed-by: Austin Clements <>
Trust: Michael Pratt <>
diff --git a/src/sync/rwmutex.go b/src/sync/rwmutex.go
index dc0faf6..3012b55 100644
--- a/src/sync/rwmutex.go
+++ b/src/sync/rwmutex.go
@@ -35,6 +35,19 @@
 const rwmutexMaxReaders = 1 << 30
+// Happens-before relationships are indicated to the race detector via:
+// - Unlock  -> Lock:  readerSem
+// - Unlock  -> RLock: readerSem
+// - RUnlock -> Lock:  writerSem
+// The methods below temporarily disable handling of race synchronization
+// events in order to provide the more precise model above to the race
+// detector.
+// For example, atomic.AddInt32 in RLock should not appear to provide
+// acquire-release semantics, which would incorrectly synchronize racing
+// readers, thus potentially missing races.
 // RLock locks rw for reading.
 // It should not be used for recursive read locking; a blocked Lock