-
Notifications
You must be signed in to change notification settings - Fork 18k
Selects are always selecting the first case if multiple can proceed #2152
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
Labels
Comments
the bug was introduced with release 9237: $ hg log -r 9237 changeset: 9237:2ccdb29d715c user: Dmitriy Vyukov <[email protected]> date: Thu Jul 21 13:57:13 2011 -0400 summary: runtime: faster select 9236 behaves as per the spec. |
sorry, 9236 and 9237 are local numbers relevant to my repository. this is the revision that introduced the bug: http://code.google.com/p/go/source/detail?r=2ccdb29d715c |
Owner changed to @niemeyer. Status changed to Started. |
Here is test/fixedbugs/bug2152.go // $G $D/$F.go && $L $F.$A && ./$A.out // Copyright 2011 The Go Authors. All rights reserved. // Use of this source code is governed by a BSD-style // license that can be found in the LICENSE file. package main import ( "runtime" ) func main() { const N = 100 const K = 10 c := make(chan int) go func() { zeros := 0 for i := 0; i < N; i++ { runtime.Gosched() if <-c == 0 { zeros++ } } if zeros <= N/K || zeros >= N-N/K { println("zeros=", zeros, "ones=", N-zeros) panic("select cases are not that random") } c <- 0 }() for i := 0; i < N; i++ { select { case c <- 0: case c <- 1: } } <-c } |
Here is the fix diff -r 4dfd650363a2 src/pkg/runtime/chan.c --- a/src/pkg/runtime/chan.c Mon Aug 15 15:16:57 2011 +1000 +++ b/src/pkg/runtime/chan.c Mon Aug 15 10:21:57 2011 +0400 @@ -904,7 +904,8 @@ // pass 2 - enqueue on all chans for(i=0; i<sel->ncase; i++) { - cas = &sel->scase[i]; + o = sel->pollorder[i]; + cas = &sel->scase[o]; c = cas->chan; sg = &cas->sg; sg->g = g; |
It's in review with test and all: http://golang.org/cl/4888044/ |
This issue was closed by revision 1758492. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by bjorn.tipling:
The text was updated successfully, but these errors were encountered: