Skip to content
New issue

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

An empty for{} will block large slice allocation in another goroutine, even with GOMAXPROCS > 1 ? #17174

Closed
yaofu1986 opened this issue Sep 21, 2016 · 5 comments

Comments

@yaofu1986
Copy link

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version go1.6.1 darwin/amd64

What operating system and processor architecture are you using (go env)?

GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"
GOPATH="/Users/yaofu/go"
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 (
    "runtime"
)

func work() {
    println("before")
    s := make([]int, 6000000)
    println("after")
    s[0] = 1
}

func main() {
    runtime.GOMAXPROCS(4)

    //work()   // This is OK. Very quick.
    go work()

    for {
    }
}

PS: I know for{} busy wait is no good. But I'm curious to know the underlying reason.

What did you expect to see?

following print:

before
after

What did you see instead?

following printed:

before
@randall77
Copy link
Contributor

Go has a cooperative, not preemptive, scheduler. The for{} loop never reaches a preemption point, so a garbage collection cannot complete.
Dup of #10958

@ianlancetaylor
Copy link
Contributor

If you want to block forever, use select {}.

@quentinmit
Copy link
Contributor

Can/should the compiler automatically turn for {} into select {}?

On Sep 21, 2016 09:11, "Ian Lance Taylor" notifications@github.com wrote:

If you want to block forever, use select {}.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#17174 (comment), or mute
the thread
https://github.com/notifications/unsubscribe-auth/AAHEMWI0mZF8FIy7xSwyfhN07SZLFkxNks5qsS0BgaJpZM4KCasB
.

@ianlancetaylor
Copy link
Contributor

It could but I don't think it's worth it. Nobody writes for {} in real code.

@minux
Copy link
Member

minux commented Sep 22, 2016 via email

@golang golang locked and limited conversation to collaborators Sep 22, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants