[go-nuts] Re: ctrl-c and Golang

2019-02-18 Thread Hemant Singh
Thanks all for replying. I will look into what solution would work best and get back. Zhipeng, I cannot add a sleep inside the for loop because the loop is sending network packets as fast as possible. Best, Hemant On Monday, February 18, 2019 at 1:41:16 AM UTC-5, Zhipeng Wang wrote: > >

[go-nuts] Re: ctrl-c and Golang

2019-02-17 Thread Zhipeng Wang
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.

Re: [go-nuts] Re: ctrl-c and Golang

2019-02-17 Thread Jan Mercl
On Mon, Feb 18, 2019 at 3:10 AM Louki Sumirniy < louki.sumirniy.stal...@gmail.com> wrote: > I know what it is. The closure is implicitly receiving the variable by value, so its state when the goroutine spawns is fixed into its local scope. Closures are implemented in Go using pointers to the capt

[go-nuts] Re: ctrl-c and Golang

2019-02-17 Thread Louki Sumirniy
I know what it is. The closure is implicitly receiving the variable by value, so its state when the goroutine spawns is fixed into its local scope. If you moved that variable outside of the function you would not have this problem, as another alternative solution. Incidentally, the issue of sta

[go-nuts] Re: ctrl-c and Golang

2019-02-17 Thread nanmu42
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

[go-nuts] Re: ctrl-c and Golang

2019-02-17 Thread Manlio Perillo
Your program has a data race, since you are accessing the array from two different goroutines. Manlio On Saturday, February 16, 2019 at 3:29:45 PM UTC+1, Hemant Singh wrote: > > I have the following program. The program is processing network packets > at 1 Gbps rate. I don't want to print the