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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [ken/] [chan1.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
import "runtime"
10
 
11
const N = 1000 // sent messages
12
const M = 10   // receiving goroutines
13
const W = 2    // channel buffering
14
var h [N]int   // marking of send/recv
15
 
16
func r(c chan int, m int) {
17
        for {
18
                select {
19
                case r := <-c:
20
                        if h[r] != 1 {
21
                                println("r",
22
                                        "m=", m,
23
                                        "r=", r,
24
                                        "h=", h[r])
25
                                panic("fail")
26
                        }
27
                        h[r] = 2
28
                }
29
        }
30
}
31
 
32
func s(c chan int) {
33
        for n := 0; n < N; n++ {
34
                r := n
35
                if h[r] != 0 {
36
                        println("s")
37
                        panic("fail")
38
                }
39
                h[r] = 1
40
                c <- r
41
        }
42
}
43
 
44
func main() {
45
        c := make(chan int, W)
46
        for m := 0; m < M; m++ {
47
                go r(c, m)
48
                runtime.Gosched()
49
        }
50
        runtime.Gosched()
51
        runtime.Gosched()
52
        s(c)
53
}

powered by: WebSVN 2.1.0

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