goroutines _ golang

A goroutine is a loghtweight thread of execution

package main

import (
    "fmt"
)

func f(form string) {
    for i := 0; i < 3; i++ {
        fmt.Println(form, ";", i)
    }
}

func main() {

    f("direct")

    go f("goroutine")

    go func(msg string) {
        fmt.Println(msg)
    }("going")

    var input string

    fmt.Scanln(&input)
    fmt.Println("done")
}
direct ; 0
direct ; 1
direct ; 2
goroutine ; 0
goroutine ; 1
goroutine ; 2
going
xxjkx
done

总结 :

  1 : ....

posted on 2015-03-15 14:43  xjk112  阅读(200)  评论(0编辑  收藏  举报