Skip to content

Commit

Permalink
sync: document RWMutex race semantics
Browse files Browse the repository at this point in the history
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 <[email protected]>
TryBot-Result: Go Bot <[email protected]>
Reviewed-by: Austin Clements <[email protected]>
Trust: Michael Pratt <[email protected]>
  • Loading branch information
prattmic committed Nov 18, 2020
1 parent b63db7f commit b4f3d52
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/sync/rwmutex.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b4f3d52

Please sign in to comment.