]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/go.test/test/chan/select2.go
Add Go frontend, libgo library, and Go testsuite.
[thirdparty/gcc.git] / gcc / testsuite / go.test / test / chan / select2.go
1 // $G $D/$F.go && $L $F.$A && ./$A.out
2
3 // Copyright 2010 The Go Authors. All rights reserved.
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file.
6
7 package main
8
9 import "runtime"
10
11 func sender(c chan int, n int) {
12 for i := 0; i < n; i++ {
13 c <- 1
14 }
15 }
16
17 func receiver(c, dummy chan int, n int) {
18 for i := 0; i < n; i++ {
19 select {
20 case <-c:
21 // nothing
22 case <-dummy:
23 panic("dummy")
24 }
25 }
26 }
27
28 func main() {
29 runtime.MemProfileRate = 0
30
31 c := make(chan int)
32 dummy := make(chan int)
33
34 // warm up
35 go sender(c, 100000)
36 receiver(c, dummy, 100000)
37 runtime.GC()
38 runtime.MemStats.Alloc = 0
39
40 // second time shouldn't increase footprint by much
41 go sender(c, 100000)
42 receiver(c, dummy, 100000)
43 runtime.GC()
44
45 if runtime.MemStats.Alloc > 1e5 {
46 println("BUG: too much memory for 100,000 selects:", runtime.MemStats.Alloc)
47 }
48 }