Source file
test/chan/select2.go
1
2
3
4
5
6
7
8
9 package main
10
11 import "runtime"
12
13 func sender(c chan int, n int) {
14 for i := 0; i < n; i++ {
15 c <- 1
16 }
17 }
18
19 func receiver(c, dummy chan int, n int) {
20 for i := 0; i < n; i++ {
21 select {
22 case <-c:
23
24 case <-dummy:
25 panic("dummy")
26 }
27 }
28 }
29
30 func main() {
31 runtime.MemProfileRate = 0
32
33 c := make(chan int)
34 dummy := make(chan int)
35
36
37 go sender(c, 100000)
38 receiver(c, dummy, 100000)
39 runtime.GC()
40 memstats := new(runtime.MemStats)
41 runtime.ReadMemStats(memstats)
42 alloc := memstats.Alloc
43
44
45 go sender(c, 100000)
46 receiver(c, dummy, 100000)
47 runtime.GC()
48 runtime.ReadMemStats(memstats)
49
50
51 if memstats.Alloc > alloc && memstats.Alloc-alloc > 1.1e5 {
52 println("BUG: too much memory for 100,000 selects:", memstats.Alloc-alloc)
53 }
54 }
55
View as plain text