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
runtime: scheduler randomness lost #29961
Comments
/cc @aclements @mknyszek |
I don't see this issue on linux/amd64. More often than not, the B goroutine finishes before A starts, but certainly not always. |
Historically on my Mac the reverse was true. There was at least one context switch of B to A before B finished. Sometimes more. Now on my Mac that context switch never materializes. I’ve seen the same lack of context switches in other concurrent code. |
Since others can’t reproduce, I suggest doing a git bisect, in the hopes that identifying the offending commit provides some insight. |
I was curious after seeing this issue, and was able to reproduce this on my machine (comparing
|
Quick link to the CL (since I forgot it): https://golang.org/cl/141639 |
Just to make it super easy to run (instead of scrolling through 10,000 prints), you can use
The first shows a recent commit doing all of B, then all of A, while the second shows a much older commit doing some of B, then all of A, then the rest of B. |
Thank you Jake. I honestly didn't know how to do that. |
Wouldn't a trace file make this easier to understand? And they should be running concurrently, unless GOMAXPROCS=1 and then any switch would only happen due to the serialization around the Print - so maybe the Print lock is not fair in the latest release ? |
This has been fixed on tip. My guess is because of the changes to the schedule. |
This is not an issue any longer. |
What version of Go are you using (
go version
)?1.12 beta 2
Does this issue reproduce with the latest release?
Only seeing it with 1.12 beta 2
What operating system and processor architecture are you using (
go env
)?GOARCH="amd64"
GOOS="darwin"
What did you do?
I've been using this program in training for years. It shows how random the scheduler is with context switches and it can't be predicted.
https://github.com/ardanlabs/gotraining/blob/master/topics/go/concurrency/goroutines/example2/example2.go
Just build the program and run it several times. On 1.11 or earlier, you will see the B goroutine context switches as an unpredictable prime number each time. Sometimes you get 4 context switches before it is complete. It is very rare not to get one before the work for any goroutine is complete. On 1.12, these context switches are gone. I am seeing this behavior with other programs I have. This one is the easiest to run and see the change.
What did you expect to see?
Create Goroutines
Waiting To Finish
B:2
B:3
B:5
B:7
. . .
B:4139
B:4153
B:4157
A:2 <- Unpredictable context switch
A:3
A:5
A:7
. . .
A:4231
A:4241
A:4243
B:4159 <- Unpredictable context switch
B:4177
B:4201
. . .
Completed B
. . .
A:4987
A:4993
A:4999
Completed A
What did you see instead?
Every time I run it there is no context switch. The B goroutine finishes completely and then the A goroutine runs. This happens every single time.
B:2
B:3
B:5
B:7
B:11
...
B:4987
B:4993
B:4999
Completed B
A:2
A:3
A:5
A:7
. . .
A:4987
A:4993
A:4999
Completed A
The text was updated successfully, but these errors were encountered: