aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Gerrand <adg@golang.org>2016-05-30 15:17:14 +1000
committerAndrew Gerrand <adg@golang.org>2016-05-31 00:22:56 +0000
commitb3f98d7a42d04f6f173cd61ce3fe2106e4877496 (patch)
treee3bca69a46064cb6349cd16a7f7d6404b31e3b97
parentd2c92f8453cab8d042b794c8ce398f6ff8e6f650 (diff)
downloadgo-b3f98d7a42d04f6f173cd61ce3fe2106e4877496.tar.gz
go-b3f98d7a42d04f6f173cd61ce3fe2106e4877496.zip
sync: document that RWMutex read locks may not be held recursively
Fixes #15418 Change-Id: Ibc51d602eb28819d0e44e5ca13a5c61573e4111c Reviewed-on: https://go-review.googlesource.com/23570 Reviewed-by: Dmitry Vyukov <dvyukov@google.com>
-rw-r--r--src/sync/rwmutex.go17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/sync/rwmutex.go b/src/sync/rwmutex.go
index 455d412330..6734360e37 100644
--- a/src/sync/rwmutex.go
+++ b/src/sync/rwmutex.go
@@ -11,13 +11,17 @@ import (
)
// An RWMutex is a reader/writer mutual exclusion lock.
-// The lock can be held by an arbitrary number of readers
-// or a single writer.
-// RWMutexes can be created as part of other
-// structures; the zero value for a RWMutex is
-// an unlocked mutex.
+// The lock can be held by an arbitrary number of readers or a single writer.
+// RWMutexes can be created as part of other structures;
+// the zero value for a RWMutex is an unlocked mutex.
//
// An RWMutex must not be copied after first use.
+//
+// If a goroutine holds a RWMutex for reading, it must not expect this or any
+// other goroutine to be able to also take the read lock until the first read
+// lock is released. In particular, this prohibits recursive read locking.
+// This is to ensure that the lock eventually becomes available;
+// a blocked Lock call excludes new readers from acquiring the lock.
type RWMutex struct {
w Mutex // held if there are pending writers
writerSem uint32 // semaphore for writers to wait for completing readers
@@ -73,9 +77,6 @@ func (rw *RWMutex) RUnlock() {
// Lock locks rw for writing.
// If the lock is already locked for reading or writing,
// Lock blocks until the lock is available.
-// To ensure that the lock eventually becomes available,
-// a blocked Lock call excludes new readers from acquiring
-// the lock.
func (rw *RWMutex) Lock() {
if race.Enabled {
_ = rw.w.state