-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.
Milestone
Description
Please answer these questions before submitting your issue. Thanks!
- What version of Go are you using (
go version)?
go version go1.6 darwin/amd64 - What operating system and processor architecture are you using (
go env)?
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH=""
GORACE=""
GOROOT="/usr/local/go"
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GO15VENDOREXPERIMENT="1"
CC="clang"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fno-common"
CXX="clang++"
CGO_ENABLED="1" - What did you do?
package main
import (
"fmt"
"sync"
)
func main() {
ch := make(chan int)
testFunc := func() {
weirdLock := sync.RWMutex{}
go func() {
weirdLock.RLock()
go func() {
weirdLock.RLock()
for i := 0; i < 3; i++ {
func() {
weirdLock.RLock()
ch <- 1
weirdLock.RUnlock()
}()
}
weirdLock.RUnlock()
}()
weirdLock.RUnlock()
}()
go func() {
weirdLock.Lock()
ch <- 1
weirdLock.Unlock()
}()
}
runNum := 1000
for i := 0; i < runNum; i++ {
testFunc()
}
total := 0
for i := 0; i < 4*runNum; i++ {
total += <-ch
}
//Expect 4*runNum
fmt.Println(total)
}http://play.golang.org/p/UWIAmPCRCu
- What did you expect to see?
output 4000 - What did you see instead?
fatal error: all goroutines are asleep - deadlock!
runNum more big,the probability of deadlock more often
Metadata
Metadata
Assignees
Labels
DocumentationIssues describing a change to documentation.Issues describing a change to documentation.FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.The path to resolution is known, but the work has not been done.