There may be something else in your code that is accidentally wrong. For debug, try printing time_array in every loop.
I built a similar program for debug, where all seems to be good: ```go package main import ( "fmt" "time" ) func main() { var a [32]int go func() { time.Sleep(1 * time.Second) fmt.Println("goroutine:", a) }() a[1] = 4 { a[2] = 6 } fmt.Println("main:", a) time.Sleep(5*time.Second) } ``` 在 2019年2月16日星期六 UTC+8下午10:29:45,Hemant Singh写道: > > I have the following program. The program is processing network packets > at 1 Gbps rate. I don't want to print the rate for every packet. Instead, > I'd like to save the rate in an array and dump the array on Ctrl-c of the > program. When I dump the array on Ctrl-c, the data is all zeroes. Please > see "<===" in the program below. Anything else one could do? > > Thanks. > > -Hemant > > func main() { > > const SZ = 65536 > var time_array [SZ]float64 > > c := make(chan os.Signal) > signal.Notify(c, os.Interrupt, syscall.SIGTERM) > > go func() { > <-c > fmt.Printf("You pressed ctrl + C. User interrupted infinite loop.") > fmt.Printf("%v ", time_array); <=== all zeroes printed. > os.Exit(0) > }() > > > i := 0 > for { > ... > time_array[i] = rate > fmt.Printf("%f bps ", rate) <=== value printed is correct. > i++ > } > } > > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.