diff options
author | Austin Clements <austin@google.com> | 2017-06-28 15:54:46 -0400 |
---|---|---|
committer | Austin Clements <austin@google.com> | 2017-06-28 22:08:57 +0000 |
commit | 80832974ac9306f992c797f8394e44d7f63f307e (patch) | |
tree | f1a58abffb5da95e8a37ece53339ac485fc6cab9 /src/runtime/rwmutex_test.go | |
parent | 3ea53cb08f1709b2f9bf39cfcfaa1d285256baa2 (diff) | |
download | go-80832974ac9306f992c797f8394e44d7f63f307e.tar.gz go-80832974ac9306f992c797f8394e44d7f63f307e.zip |
runtime: make rwmutex work on Ms instead of Gs
Currently runtime.rwmutex is written to block the calling goroutine
rather than the calling thread. However, rwmutex was intended to be
used in the scheduler, which means it needs to be a thread-level
synchronization primitive.
Hence, this modifies rwmutex to synchronize threads instead of
goroutines. This has the consequence of making it write-barrier-free,
which is also important for using it in the scheduler.
The implementation makes three changes: it replaces the "w" semaphore
with a mutex, since this was all it was being used for anyway; it
replaces "writerSem" with a single pending M that parks on its note;
and it replaces "readerSem" with a list of Ms that park on their notes
plus a pass count that together emulate a counting semaphore. I
model-checked the safety and liveness of this implementation through
>1 billion schedules.
For #20738.
Change-Id: I3cf5a18c266a96a3f38165083812803510217787
Reviewed-on: https://go-review.googlesource.com/47071
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Diffstat (limited to 'src/runtime/rwmutex_test.go')
-rw-r--r-- | src/runtime/rwmutex_test.go | 4 |
1 files changed, 0 insertions, 4 deletions
diff --git a/src/runtime/rwmutex_test.go b/src/runtime/rwmutex_test.go index f21a531256..b78a8e7987 100644 --- a/src/runtime/rwmutex_test.go +++ b/src/runtime/rwmutex_test.go @@ -27,7 +27,6 @@ func parallelReader(m *RWMutex, clocked, cunlock, cdone chan bool) { func doTestParallelReaders(numReaders, gomaxprocs int) { GOMAXPROCS(gomaxprocs) var m RWMutex - m.Init() clocked := make(chan bool) cunlock := make(chan bool) cdone := make(chan bool) @@ -89,7 +88,6 @@ func HammerRWMutex(gomaxprocs, numReaders, num_iterations int) { // Number of active readers + 10000 * number of active writers. var activity int32 var rwm RWMutex - rwm.Init() cdone := make(chan bool) go writer(&rwm, num_iterations, &activity, cdone) var i int @@ -131,7 +129,6 @@ func BenchmarkRWMutexUncontended(b *testing.B) { } b.RunParallel(func(pb *testing.PB) { var rwm PaddedRWMutex - rwm.RWMutex.Init() for pb.Next() { rwm.RLock() rwm.RLock() @@ -145,7 +142,6 @@ func BenchmarkRWMutexUncontended(b *testing.B) { func benchmarkRWMutex(b *testing.B, localWork, writeRatio int) { var rwm RWMutex - rwm.Init() b.RunParallel(func(pb *testing.PB) { foo := 0 for pb.Next() { |