Skip to content

Instantly share code, notes, and snippets.

@kicool
Created January 24, 2013 00:10
Show Gist options
  • Save kicool/4616096 to your computer and use it in GitHub Desktop.
Save kicool/4616096 to your computer and use it in GitHub Desktop.
closure problem when go routine and for are used together
// project
package main
import (
"fmt"
"time"
)
func main() {
for i := 0; i < 5; i++ {
go func() {
fmt.Println(i)
}()
}
time.Sleep(time.Second)
for i := 0; i < 5; i++ {
var k = i
go func() {
fmt.Println(k)
}()
}
time.Sleep(time.Second)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment