File tree 2 files changed +35
-1
lines changed
2 files changed +35
-1
lines changed Original file line number Diff line number Diff line change @@ -904,7 +904,8 @@ selectgo(Select **selp)
904
904
905
905
// pass 2 - enqueue on all chans
906
906
for (i = 0 ; i < sel -> ncase ; i ++ ) {
907
- cas = & sel -> scase [i ];
907
+ o = sel -> pollorder [i ];
908
+ cas = & sel -> scase [o ];
908
909
c = cas -> chan ;
909
910
sg = & cas -> sg ;
910
911
sg -> g = g ;
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ package runtime_test
6
6
7
7
import (
8
8
"runtime"
9
+ "sync"
9
10
"sync/atomic"
10
11
"testing"
11
12
)
@@ -26,6 +27,38 @@ func TestChanSendInterface(t *testing.T) {
26
27
}
27
28
}
28
29
30
+ func TestPseudoRandomSend (t * testing.T ) {
31
+ n := 100
32
+ c := make (chan int )
33
+ l := make ([]int , n )
34
+ var m sync.Mutex
35
+ m .Lock ()
36
+ go func () {
37
+ for i := 0 ; i < n ; i ++ {
38
+ runtime .Gosched ()
39
+ l [i ] = <- c
40
+ }
41
+ m .Unlock ()
42
+ }()
43
+ for i := 0 ; i < n ; i ++ {
44
+ select {
45
+ case c <- 0 :
46
+ case c <- 1 :
47
+ }
48
+ }
49
+ m .Lock () // wait
50
+ n0 := 0
51
+ n1 := 0
52
+ for _ , i := range l {
53
+ n0 += (i + 1 ) % 2
54
+ n1 += i
55
+ if n0 > n / 10 && n1 > n / 10 {
56
+ return
57
+ }
58
+ }
59
+ t .Errorf ("Want pseudo random, got %d zeros and %d ones" , n0 , n1 )
60
+ }
61
+
29
62
func BenchmarkSelectUncontended (b * testing.B ) {
30
63
const CallsPerSched = 1000
31
64
procs := runtime .GOMAXPROCS (- 1 )
You can’t perform that action at this time.
0 commit comments