From d41dfadd0002d5e3057a86af70ad607930f5ef19 Mon Sep 17 00:00:00 2001 From: xland <412588801@qq.com> Date: Thu, 3 Jan 2013 13:17:05 +0800 Subject: [PATCH] Update 2.7.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 这里能在多解释解释runtime.Gosched()就好了,这一章感觉写的东西不够细啊。 --- 2.7.md | 1 + 1 file changed, 1 insertion(+) diff --git a/2.7.md b/2.7.md index 006be415..4f001cc0 100644 --- a/2.7.md +++ b/2.7.md @@ -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: