source: doc/theses/colby_parsons_MMAth/benchmarks/channels/go/ping_pong/ping_pong.go @ f3d2a4f

Last change on this file since f3d2a4f was e2f827f, checked in by caparson <caparson@…>, 16 months ago

added go counterpart to cfa benchmarks

  • Property mode set to 100644
File size: 661 bytes
Line 
1package main
2
3import (
4        "fmt"
5        "time"
6        "runtime"
7)
8
9var done bool = false;
10var total_operations uint64 = 0
11
12var taskJoin chan int = make(chan int, 2)
13
14var ping chan int = make(chan int, 2 )
15var pong chan int = make(chan int, 2 )
16
17func Ping() {
18        for {
19                if done { break }
20                pong <- 1
21                <-ping
22        }
23        taskJoin <- 0
24}
25
26func Pong() {
27        for {
28                if done { break }
29                <-pong
30                ping <- 0
31                total_operations++
32        }
33        taskJoin <- 0
34}
35
36func main() {
37        runtime.GOMAXPROCS( 2 );
38
39        go Ping()
40        go Pong()
41               
42        // wait 10 seconds
43        time.Sleep(time.Second * 10)
44        // fmt.Println("prod done\n")
45        done = true
46
47        ping <- 2
48        pong <- 2
49
50        <-taskJoin
51        <-taskJoin
52
53    fmt.Println(total_operations)
54}
Note: See TracBrowser for help on using the repository browser.