Skip to content

Instantly share code, notes, and snippets.

@xiaojay
Created June 27, 2013 03:54
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 xiaojay/5873816 to your computer and use it in GitHub Desktop.
Save xiaojay/5873816 to your computer and use it in GitHub Desktop.
test for observe num of goroutine running http://v2ex.com/t/73772#reply1
package main
import (
"fmt"
"time"
"math/rand"
"runtime"
)
func get_rand_int(max int) int {
rand.Seed( time.Now().UTC().UnixNano())
return rand.Intn(max)
}
func report() {
for {
fmt.Println("目前goroutine数目", runtime.NumGoroutine())
time.Sleep(1000*time.Millisecond)
}
}
func routine(){
n := get_rand_int(10000)
time.Sleep(time.Duration(n) * time.Millisecond)
}
func main() {
go report()
for{
time.Sleep(500*time.Millisecond)
go routine()
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment