Merge pull request #135 from xland/patch-1

Update 2.7.md
This commit is contained in:
astaxie
2013-01-02 23:04:31 -08:00

1
2.7.md
View File

@@ -43,6 +43,7 @@ Goroutines是通过Go的runtime管理的一个线程管理器。Goroutines通过
hello
我们可以看到go关键字很方便的就实现了并发编程。
runtime.Gosched()表示让CPU把时间片让给别人。
## channels
Goroutines运行在相同的地址空间因此访问共享内存必须做好同步。那么Goroutines之间如何进行数据的通信呢Go提供了一个很好的通信机制channel。channel可以与Unix shell 中的双向管道做类比可以通过它发送或者接收值。这些值只能是特定的类型channel类型。定义一个channel 时也需要定义发送到channel 的值的类型。注意必须使用make 创建channel