Skip to content

Instantly share code, notes, and snippets.

@dr2chase
Created June 20, 2016 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dr2chase/fdda77c0f2d18e832fcd23f719daa24a to your computer and use it in GitHub Desktop.
Save dr2chase/fdda77c0f2d18e832fcd23f719daa24a to your computer and use it in GitHub Desktop.
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