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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [go.test/] [test/] [chan/] [goroutines.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
// make a lot of goroutines, threaded together.
8
// tear them down cleanly.
9
 
10
package main
11
 
12
import (
13
        "os"
14
        "strconv"
15
)
16
 
17
func f(left, right chan int) {
18
        left <- <-right
19
}
20
 
21
func main() {
22
        var n = 10000
23
        if len(os.Args) > 1 {
24
                var err error
25
                n, err = strconv.Atoi(os.Args[1])
26
                if err != nil {
27
                        print("bad arg\n")
28
                        os.Exit(1)
29
                }
30
        }
31
        leftmost := make(chan int)
32
        right := leftmost
33
        left := leftmost
34
        for i := 0; i < n; i++ {
35
                right = make(chan int)
36
                go f(left, right)
37
                left = right
38
        }
39
        go func(c chan int) { c <- 1 }(right)
40
        <-leftmost
41
}

powered by: WebSVN 2.1.0

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