-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
Comments
Go has a cooperative, not preemptive, scheduler. The |
If you want to block forever, use |
Can/should the compiler automatically turn for {} into select {}? On Sep 21, 2016 09:11, "Ian Lance Taylor" notifications@github.com wrote:
|
It could but I don't think it's worth it. Nobody writes |
The for {} problem is only one special case of a non-preemptible loop. I
don't think the compiler should handle this one case but not the others.
However, handling the general problem is very hard because sometimes people
do write such tight loops to crunch data, for example, and the compiler
shouldn't insert preemption points into such deliberate tight loops.
I couldn't think of any valid use of for {} except toy examples, so I think
the status quo is fine.
|
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
)?What did you do?
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:
What did you see instead?
following printed:
The text was updated successfully, but these errors were encountered: