I think this is a bug, I change the logic of main goroutine and the other goroutine, then the deadlock disappeared ```go package main
import ( "fmt" "time" ) var ( source = make(chan int) idle = make(chan int, 1) ) func main() { go func() { for { select { case worker := <-source: idle <- worker case worker := <-idle: fmt.Println(worker) go func() { time.Sleep(time.Second) idle <- 1 }() } } }() for i := 0; i < 2; i++ { source <- i } time.Sleep(time.Second * 10) } ``` 在 2018年2月7日星期三 UTC+8下午10:38:41,Damon Zhao写道: > > Please answer these questions before submitting your issue. Thanks! > What version of Go are you using (go version)? > > go version go1.9.3 darwin/amd64 > Does this issue reproduce with the latest release? > > yes > What operating system and processor architecture are you using (go env)? > GOARCH="amd64" > GOBIN="" > GOEXE="" > GOHOSTARCH="amd64" > GOHOSTOS="darwin" > GOOS="darwin" > GOPATH="/Users/ariesdevil/Dropbox/workspace/go_workspace" > GORACE="" > GOROOT="/usr/local/Cellar/go/1.9.3/libexec" > GOTOOLDIR="/usr/local/Cellar/go/1.9.3/libexec/pkg/tool/darwin_amd64" > GCCGO="gccgo" > CC="clang" > GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments > -fmessage-length=0 > -fdebug-prefix-map=/var/folders/h2/xl15t9g94tgfwclshzl086bh0000gp/T/go-build125147941=/tmp/go-build > > -gno-record-gcc-switches -fno-common" > CXX="clang++" > CGO_ENABLED="1" > CGO_CFLAGS="-g -O2" > CGO_CPPFLAGS="" > CGO_CXXFLAGS="-g -O2" > CGO_FFLAGS="-g -O2" > CGO_LDFLAGS="-g -O2" > PKG_CONFIG="pkg-config" > > What did you do? > > code1: play.golang.org/p/8rcO11QS8un (@ianlancetaylor answerd at > https://github.com/golang/go/issues/23728#issuecomment-363771924) > > > code2: https://play.golang.org/p/fJXhK8w22uu > > Above code2 sometimes run perfect and sometimes deadlock on my machine. > > > <https://lh3.googleusercontent.com/-j-2Sg_4wENk/WnsPXZktt7I/AAAAAAAAb9M/vI8Ci9g8k9gZ_83XWS6qgR2bxjuHN8w1ACLcBGAs/s1600/%25E5%25B1%258F%25E5%25B9%2595%25E5%25BF%25AB%25E7%2585%25A7%2B2018-02-07%2B22.10.22.png> > > > > But if I put it in a goroutine, the result is confused: > > > https://play.golang.org/p/oUmMr8TM2sz success > > https://play.golang.org/p/54eLI7x5FwD failed > > > notice line 25 when I use > > ``` > > case worker := <-source: > > idle <- worker > > ``` > > instead of: > > ``` > > case idle <- <-source: > > ``` > > it works. > What did you expect to see? > > I think it should not deadlock. > What did you see instead? > deadlock sometimes. > > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.