OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [chan/] [select.go] - Blame information for rev 700

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 700 jeremybenn
// $G $D/$F.go && $L $F.$A && ./$A.out
2
 
3
// Copyright 2009 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
var counter uint
10
var shift uint
11
 
12
func GetValue() uint {
13
        counter++
14
        return 1 << shift
15
}
16
 
17
func Send(a, b chan uint) int {
18
        var i int
19
 
20
LOOP:
21
        for {
22
                select {
23
                case a <- GetValue():
24
                        i++
25
                        a = nil
26
                case b <- GetValue():
27
                        i++
28
                        b = nil
29
                default:
30
                        break LOOP
31
                }
32
                shift++
33
        }
34
        return i
35
}
36
 
37
func main() {
38
        a := make(chan uint, 1)
39
        b := make(chan uint, 1)
40
        if v := Send(a, b); v != 2 {
41
                println("Send returned", v, "!= 2")
42
                panic("fail")
43
        }
44
        if av, bv := <-a, <-b; av|bv != 3 {
45
                println("bad values", av, bv)
46
                panic("fail")
47
        }
48
        if v := Send(a, nil); v != 1 {
49
                println("Send returned", v, "!= 1")
50
                panic("fail")
51
        }
52
        if counter != 10 {
53
                println("counter is", counter, "!= 10")
54
                panic("fail")
55
        }
56
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.