diff --git a/doc/go_spec.html b/doc/go_spec.html index 2f6fd2b97e..8a7e8ec032 100644 --- a/doc/go_spec.html +++ b/doc/go_spec.html @@ -1,6 +1,6 @@ @@ -1331,8 +1331,8 @@ make(chan int, 100)
The capacity, in number of elements, sets the size of the buffer in the channel.
If the capacity is zero or absent, the channel is unbuffered and communication
-succeeds only when both a sender and receiver are ready. Otherwise, the channel is
-buffered and communication operations succeed without blocking if the buffer
+succeeds only when both a sender and receiver are ready. Otherwise, the channel
+is buffered and communication succeeds without blocking if the buffer
is not full (sends) or not empty (receives).
A nil channel is never ready for communication.
-A "select" statement chooses which of a set of possible communications -will proceed. It looks similar to a "switch" statement but with the +A "select" statement chooses which of a set of possible +send or +receive +operations will proceed. +It looks similar to a +"switch" statement but with the cases all referring to communication operations.
@@ -4893,41 +4897,63 @@ RecvExpr = Expression .
-RecvExpr must be a receive operation.
-For all the cases in the "select"
-statement, the channel expressions are evaluated in top-to-bottom order, along with
-any expressions that appear on the right hand side of send statements.
-A channel may be nil,
-which is equivalent to that case not
-being present in the select statement
-except, if a send, its expression is still evaluated.
-If any of the resulting operations can proceed, one of those is
-chosen and the corresponding communication and statements are
-evaluated. Otherwise, if there is a default case, that executes;
-if there is no default case, the statement blocks until one of the communications can
-complete. There can be at most one default case and it may appear anywhere in the
-"select" statement.
-If there are no cases with non-nil channels,
-the statement blocks forever.
-Even if the statement blocks,
-the channel and send expressions are evaluated only once,
-upon entering the select statement.
-
-Since all the channels and send expressions are evaluated, any side -effects in that evaluation will occur for all the communications -in the "select" statement. -
--If multiple cases can proceed, a uniform pseudo-random choice is made to decide -which single communication will execute. -
-The receive case may declare one or two new variables using a +A case with a RecvStmt may assign the result of a RecvExpr to one or +two variables, which may be declared using a short variable declaration. +The RecvExpr must be a (possibly parenthesized) receive operation. +There can be at most one default case and it may appear anywhere +in the list of cases. +
+ ++Execution of a "select" statement proceeds in several steps: +
+ +
+Since communication on nil channels can never proceed,
+a select with only nil channels and no default case blocks forever.
-var c, c1, c2, c3 chan int
+var a []int
+var c, c1, c2, c3, c4 chan int
var i1, i2 int
select {
case i1 = <-c1:
@@ -4940,6 +4966,10 @@ case i3, ok := (<-c3): // same as: i3, ok := <-c3
} else {
print("c3 is closed\n")
}
+case a[f()] = <-c4:
+ // same as:
+ // case t := <-c4
+ // a[f()] = t
default:
print("no communication\n")
}