aboutsummaryrefslogtreecommitdiff
path: root/src/sync
diff options
context:
space:
mode:
authorMichael Pratt <mpratt@google.com>2020-11-17 16:47:08 -0500
committerMichael Pratt <mpratt@google.com>2020-11-18 20:12:03 +0000
commitb4f3d52f6a90aa520799f836e5951d5cf65f7fe4 (patch)
treece96a7325b6798166b2af41cedb37a51c3aaed80 /src/sync
parentb63db7f72446753de0f5bb78b629dbe58fb15cda (diff)
downloadgo-b4f3d52f6a90aa520799f836e5951d5cf65f7fe4.tar.gz
go-b4f3d52f6a90aa520799f836e5951d5cf65f7fe4.zip
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 Reviewed-on: https://go-review.googlesource.com/c/go/+/270865 Run-TryBot: Michael Pratt <mpratt@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Austin Clements <austin@google.com> Trust: Michael Pratt <mpratt@google.com>
Diffstat (limited to 'src/sync')
-rw-r--r--src/sync/rwmutex.go13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/sync/rwmutex.go b/src/sync/rwmutex.go
index dc0faf6a60..3012b5548e 100644
--- a/src/sync/rwmutex.go
+++ b/src/sync/rwmutex.go
@@ -35,6 +35,19 @@ type RWMutex struct {
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