创建一个协程
golang创建协程的关键字是
go
- go xxxx()
package mainimport ("fmt""time")func task(id int) {for {fmt.Println("child task:",id)time.Sleep(1*time.Second)}}func main() {go task(1)go task(2)go task(3)for {}}
child task: 1child task: 2child task: 3child task: 3child task: 1child task: 2
