golang channel go 线程使用方法

package main

import (
    "fmt"
    "time"
)

func main() {
    fmt.Println("running...", 123)

    ci := make(chan int, 2)

    go func() {
        i := <-ci
        fmt.Println("go 1", i)
    }()

    go func() {
        n := 1000
        for {
            time.Sleep(5 * time.Second)
            ci <- n
            fmt.Println("go 2", n)
            n++
        }
    }()
    i := <-ci
    fmt.Println("main", i)
    fmt.Scanln()
    fmt.Println("end")
}


发表于:2016-11-12 15:49:40

原文链接(转载请保留): http://www.multisilicon.com/blog/a36315958.html

友情链接: MICROIC
首页