package main
import (
"fmt"
"sync"
"time"
)
var waiter sync.WaitGroup
func print5(i int) {
j := i
for j < i+5 {
fmt.Println(j)
j++
}
waiter.Done()
}
func main() {
fmt.Println("Start print 75")
waiter = sync.WaitGroup{}
waiter.Add(15)
for i := 1; i < 75; i += 5 {
go print5(i)
time.Sleep(1 * time.Nanosecond)
}
waiter.Wait()
fmt.Println("End print 75")
}
程序输出如下,