Created
June 20, 2016 19:03
-
-
Save dr2chase/fdda77c0f2d18e832fcd23f719daa24a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"time" | |
) | |
var v int = 99 | |
var s string | |
func foo(x, y int) (z int) { | |
s = fmt.Sprintf("x=%d, y=%d, z=%d\n", x, y, z) | |
z = x + y | |
return | |
} | |
func threads() { | |
for j := 0; j < 1000; j++ { | |
go func() { | |
for k := 0; k < 100000; k++ { | |
foo(1, 2) | |
time.Sleep(10 * time.Millisecond) | |
} | |
}() | |
} | |
} | |
func main() { | |
x := v | |
y := x * x | |
var z int | |
threads() | |
for i := 0; i < 10000; i++ { | |
z = foo(x, y) | |
} | |
fmt.Printf("z=%d\n", z) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment