Last change
on this file since 4d689e2 was
e2f827f,
checked in by caparson <caparson@…>, 17 months ago
|
added go counterpart to cfa benchmarks
|
-
Property mode set to
100644
|
File size:
661 bytes
|
Rev | Line | |
---|
[e2f827f] | 1 | package main |
---|
| 2 | |
---|
| 3 | import ( |
---|
| 4 | "fmt" |
---|
| 5 | "time" |
---|
| 6 | "runtime" |
---|
| 7 | ) |
---|
| 8 | |
---|
| 9 | var done bool = false; |
---|
| 10 | var total_operations uint64 = 0 |
---|
| 11 | |
---|
| 12 | var taskJoin chan int = make(chan int, 2) |
---|
| 13 | |
---|
| 14 | var ping chan int = make(chan int, 2 ) |
---|
| 15 | var pong chan int = make(chan int, 2 ) |
---|
| 16 | |
---|
| 17 | func Ping() { |
---|
| 18 | for { |
---|
| 19 | if done { break } |
---|
| 20 | pong <- 1 |
---|
| 21 | <-ping |
---|
| 22 | } |
---|
| 23 | taskJoin <- 0 |
---|
| 24 | } |
---|
| 25 | |
---|
| 26 | func Pong() { |
---|
| 27 | for { |
---|
| 28 | if done { break } |
---|
| 29 | <-pong |
---|
| 30 | ping <- 0 |
---|
| 31 | total_operations++ |
---|
| 32 | } |
---|
| 33 | taskJoin <- 0 |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | func 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.