Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "os"
- "runtime"
- "time"
- )
- var routines = 800
- func main() {
- printTime := func(format string, i ...interface{}) {
- fmt.Printf(fmt.Sprintf("[%s] %s", time.Now().Format(time.StampMilli), format), i...)
- }
- i := 0
- go func() {
- for {
- printTime("goroutines = %d; i = %d\n", runtime.NumGoroutine(), i)
- time.Sleep(time.Second * 2)
- }
- }()
- time.Sleep(time.Second * 5)
- printTime("create %d routines\n", routines)
- for ; i < routines; i++ {
- go func() {
- time.Sleep(time.Second * 5)
- i--
- }()
- }
- for i > 0 {
- time.Sleep(time.Second)
- }
- printTime("end of routines\n")
- time.Sleep(time.Second * 20)
- os.Exit(0)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement