File tree Expand file tree Collapse file tree 2 files changed +3
-1
lines changed Expand file tree Collapse file tree 2 files changed +3
-1
lines changed Original file line number Diff line number Diff line change @@ -104,7 +104,9 @@ Go对于已声明但未使用的变量会在编译阶段报错,比如下面的
104
104
> 如下的代码会产生错误
105
105
>
106
106
>> var a int8
107
+
107
108
>> var b int32
109
+
108
110
>> c:=a + b
109
111
>
110
112
> 另外,尽管int的长度是32 bit, 但int 与 int32并不可以互用。
Original file line number Diff line number Diff line change @@ -80,7 +80,7 @@ channel通过操作符`<-`来接收和发送数据
80
80
fmt.Println(x, y, x + y)
81
81
}
82
82
83
- 默认情况下,channel接收和发送数据都是阻塞的除非另一端已经准备好 ,这样就使得Goroutines同步变的更加的简单,而不需要显式的lock。所谓阻塞,也就是如果读取(value := <-ch)它将会被阻塞,直到有数据接收。其次,任何发送(ch<-5)将会被阻塞,直到数据被读出。无缓冲channel 是在多个goroutine之间同步很棒的工具。
83
+ 默认情况下,channel接收和发送数据都是阻塞的,除非另一端已经准备好 ,这样就使得Goroutines同步变的更加的简单,而不需要显式的lock。所谓阻塞,也就是如果读取(value := <-ch)它将会被阻塞,直到有数据接收。其次,任何发送(ch<-5)将会被阻塞,直到数据被读出。无缓冲channel 是在多个goroutine之间同步很棒的工具。
84
84
85
85
## Buffered Channels
86
86
上面我们介绍了默认的非缓存类型的channel,不过Go也允许指定channel的缓冲大小,很简单,就是channel可以存储多少元素。ch:= make(chan bool, 4),创建了可以存储4个元素的bool 型channel。在这个channel 中,前4个元素可以无阻塞的写入。当写入第5个元素时,代码将会阻塞,直到其他goroutine从channel 中读取一些元素,腾出空间。
You can’t perform that action at this time.
0 commit comments