mirror of
https://github.com/golang/go.git
synced 2024-11-21 21:11:11 +00:00
Can someone double check that code from first example really has some problems?
parent
e800242a66
commit
917f086adf
@ -6,7 +6,7 @@ When new programmers start using Go or when old Go programmers start using a new
|
||||
|
||||
# Using goroutines on loop iterator variables
|
||||
|
||||
When iterating in Go, one might also be tempted to use goroutines to process data in parallel. For example, you might write the following code:
|
||||
When iterating in Go, one might also be tempted to use goroutines to process data in parallel. For example, you might write the following code (TODO: What is wrong with example from the following code?):
|
||||
```go
|
||||
for val := range values {
|
||||
go val.my_method()
|
||||
@ -62,4 +62,4 @@ for i := 1; i <= 10; i++ {
|
||||
|
||||
Even though the closures all still close over the same variable (in this case, ` i `), they are executed before the variable changes, resulting in the desired behavior.
|
||||
|
||||
http://golang.org/doc/go_faq.html#closures_and_goroutines
|
||||
http://golang.org/doc/go_faq.html#closures_and_goroutines
|
Loading…
Reference in New Issue
Block a user