golang 协程

package main
import (
    "fmt"
    "sync"
    "time"
)
var limitMaxNum = 10
var chData = make(chan int, limitMaxNum)
var jobGroup sync.WaitGroup
var tasknum = 100
func main() {
    var i int
    var j int
    //组装任务
    chanTask := make(chan int, tasknum)
    for j = 0; j < tasknum; j++ {
        chanTask <- j
    }
    close(chanTask)
    jobGroup.Add(tasknum)
    for i = 0; i < limitMaxNum; i++ { //最多10个协程
        go dotask3(chanTask)
    }
    jobGroup.Wait()
    fmt.Println("main over")
}
func dotask3(taskChan chan int) {
    for taskid := range taskChan { //每个协程拼命抢夺任务,直到任务完结
        time.Sleep(time.Millisecond * 500)
        fmt.Println("finish task ", taskid)
        jobGroup.Done()
    }
}