1. 程式人生 > >Golnag中的並發編程-協程的實現

Golnag中的並發編程-協程的實現

執行函數 執行 fmt 函數名 UNC 使用 輕量級 out 並發

協程 輕量級,通過goroutine實現協程
使用方法:go + 函數名:啟動一個協程執行函數體

package main

import (
    "fmt"
    "time"

)
func testRoutine()  {
    fmt.Println("this is one routine!!!")

}

func main()  {
    //執行協程
    go testRoutine()
    time.Sleep(1)

}

//協程與線程的關系

Golnag中的並發編程-協程的實現