We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
go version
$ go version
go version go1.11.4 linux/amd64
yes
go env
ubuntu18.04 amd64
$ go env
I run the following code:
package main import ( "fmt" "runtime" "time" ) func main() { go func() { for { } }() go func() { cnt := 1 for { time.Sleep(100 * time.Millisecond) cnt = cnt + 1 fmt.Println(cnt) if cnt == 10 { runtime.GC() } } }() ch := make(chan struct{}) <-ch }
I hope to see the number of non-stop output increases.
When cnt is 10, the program will be deadlock
Why do infinite loops and gc lead to deadlocks, and can't the dead loop be seized?
The text was updated successfully, but these errors were encountered:
The following code will still be deadlock:
package main import ( "fmt" "runtime" "time" ) func main() { go func() { cnt := 1 for { cnt++ } }() go func() { cnt := 1 for { time.Sleep(100 * time.Millisecond) cnt = cnt + 1 fmt.Println(cnt) if cnt == 10 { runtime.GC() } } }() ch := make(chan struct{}) <-ch }
The following code will not:
package main import ( "encoding/base64" "fmt" "runtime" "time" ) func main() { go func() { for { base64.StdEncoding.EncodeToString([]byte("a")) } }() go func() { cnt := 1 for { time.Sleep(100 * time.Millisecond) cnt = cnt + 1 fmt.Println(cnt) if cnt == 10 { runtime.GC() } } }() ch := make(chan struct{}) <-ch }
According to the phenomenon, the goroutine that call other packages will be preempted. why? Is it a deliberate design or a bug?
Sorry, something went wrong.
See the discussion in #10958.
@ianlancetaylor thank you
No branches or pull requests
What version of Go are you using (
go version
)?go version go1.11.4 linux/amd64
Does this issue reproduce with the latest release?
yes
What operating system and processor architecture are you using (
go env
)?ubuntu18.04 amd64
go env
OutputGOARCH="amd64"
GOBIN="/home/robin/go/bin"
GOCACHE="/root/.cache/go-build"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/go"
GOPROXY=""
GORACE=""
GOROOT="/home/robin/go"
GOTMPDIR=""
GOTOOLDIR="/home/robin/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
CXX="g++"
CGO_ENABLED="1"
GOMOD=""
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build746074640=/tmp/go-build -gno-record-gcc-switches"
What did you do?
I run the following code:
What did you expect to see?
I hope to see the number of non-stop output increases.
What did you see instead?
When cnt is 10, the program will be deadlock
my confusion
Why do infinite loops and gc lead to deadlocks, and can't the dead loop be seized?
The text was updated successfully, but these errors were encountered: