I have make a test in version go1.11.4 windows/amd64:

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 i < SZ {
      time_array[i] = 1
      fmt.Printf("%f bps ", time_array[i]) //<=== value printed is correct.
      time.Sleep(time.Second * 1)
      i++
   }
}


the result is :


1.000000 bps 1.000000 bps 1.000000 bps 1.000000 bps 1.000000 bps 1.000000 bps 
1.000000 bps 1.000000 bps 1.000000 bps You pressed ctrl + C. User interrupted 
infinite loop.[1 1 1 1 1 1
 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...0]


so, I think that others wrong in your code.



在 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.

Reply via email to