协程 轻量级,通过goroutine实现协程
使用方法:go + 函数名:启动一个协程执行函数体
package main
import (
"fmt"
"time"
)
func testRoutine() {
fmt.Println("this is one routine!!!")
}
func main() {
//执行协程
go testRoutine()
time.Sleep(1)
}
//协程与线程的关系
原文地址:http://blog.51cto.com/huwho/2307638
时间: 2024-12-18 12:45:28