首页 > 其他 > 详细

channel synchronization _ golang

时间:2015-03-16 14:14:56      阅读:258      评论:0      收藏:0      [点我收藏+]

we can use channels to sychronize execution across goroutines. Here‘s an example of using a blocking receive to to wait for a goroutine to finsh

package main

import (
    "fmt"
    "time"
)

func worker(done chan bool) {
    fmt.Println("working..")
    time.Sleep(time.Second)
    fmt.Println("done")
    done <- true
}

func main() {

    done := make(chan bool, 1)
    go worker(done)
    fmt.Println("done", <-done)
    fmt.Println(<-done)
}
working..
done
done true

总结 :

   1 : .......

channel synchronization _ golang

原文:http://www.cnblogs.com/jackkiexu/p/4341615.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!