Skip to content

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

Closed
@yaofu1986

Description

@yaofu1986

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions