]> Cypherpunks repositories - gostls13.git/commit
runtime: prevent descheduling while holding rwmutex read lock
authorAustin Clements <austin@google.com>
Thu, 6 Jul 2017 15:55:39 +0000 (11:55 -0400)
committerAustin Clements <austin@google.com>
Thu, 6 Jul 2017 17:04:25 +0000 (17:04 +0000)
commitf3b5a2bc1983ddb83d72e741b176993d9b800faf
treeeecbf8b578dc74f1db946744c7e3426d70f3751e
parentbb3be403e79731b208c41bd170a6a87642d988da
runtime: prevent descheduling while holding rwmutex read lock

Currently only the rwmutex write lock prevents descheduling. The read
lock does not. This leads to the following situation:

1. A reader acquires the lock and gets descheduled.

2. GOMAXPROCS writers attempt to acquire the lock (or at least one
writer does, followed by readers). This blocks all of the Ps.

3. There is no 3. The descheduled reader never gets to run again
because there are no Ps, so it never releases the lock and the system
deadlocks.

Fix this by preventing descheduling while holding the read lock. This
requires also rewriting TestParallelRWMutexReaders to always create
enough GOMAXPROCS and to use non-blocking operations for
synchronization.

Fixes #20903.

Change-Id: Ibd460663a7e5a555be5490e13b2eaaa295fac39f
Reviewed-on: https://go-review.googlesource.com/47632
Run-TryBot: Austin Clements <austin@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
src/runtime/rwmutex.go
src/runtime/rwmutex_test.go