Re: [go-nuts] function with goroutine returned will kill its goroutine?

2016-07-06 Thread Christoph Berger
Good point, thanks. Yes, when the process exits, the goroutines end immediately without running their defer functions. > Am 06.07.2016 um 16:47 schrieb Paul Borman : > > You probably should say all goroutines are terminated when main exits (or > os.Exit is called or the program abnormally term

Re: [go-nuts] function with goroutine returned will kill its goroutine?

2016-07-06 Thread 'Paul Borman' via golang-nuts
You probably should say all goroutines are terminated when main exits (or os.Exit is called or the program abnormally terminates), lest someone complain that their defer functions were not run. On Tue, Jul 5, 2016 at 12:29 PM, Christoph Berger < christoph.g.ber...@gmail.com> wrote: > In addition

Re: [go-nuts] function with goroutine returned will kill its goroutine?

2016-07-05 Thread Christoph Berger
In addition to that, all goroutines exit when the main function exits. In your code, this happens when i == 5. This explains the output that you get. Both goroutines are able to produce five numbers until the main loop finishes and the main function exits. On Monday, July 4, 2016 at 5:13:39 PM

Re: [go-nuts] function with goroutine returned will kill its goroutine?

2016-07-04 Thread Jan Mercl
On Mon, Jul 4, 2016 at 5:08 PM Kenshin Wang wrote: go func(i int) { for { next <- i i++ } }(start) > could anyone can explain why the output is this? A goroutine dies when it returns. A goroutine wit

[go-nuts] function with goroutine returned will kill its goroutine?

2016-07-04 Thread Kenshin Wang
> > > package main > > import "fmt" > > func main() { > ca := createCounter(2) > cb := createCounter(102) > for i := 0; i < 5; i++ { > a := <-ca > fmt.Printf("A %d \nB %d \n", a, <-cb) > } > > } > > func createCounter(start int) chan int { > next := make(chan int) > go func(i int) { > for { > next