There are two odd things.
I made 1000 numbers in slice but it just print 246,why 246?and why not 1000?
if I delete "log.Println("hey")"this line,why does it just print 0?
I know it may has sync problem,but i haven't write any concurrence programs before,so any article can recommend?
import (
"log"
"runtime"
)
func main() {
count := 1000
slice := make([] int,count)
for i := 0; i <= count-1; i++ {
slice[i] =i
}
for _,v := range slice{
go echo(v)
}
log.Println("hey")//if delete this line,it just print 0
runtime.Gosched()
}
func echo(v int) {
log.Println(v)
}