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 <bor...@google.com>:
> 
> 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 <mailto:christoph.g.ber...@gmail.com>> wrote:
> 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 UTC+2, Jan Mercl wrote:
> 
> On Mon, Jul 4, 2016 at 5:08 PM Kenshin Wang <kenshi...@gmail.com <>> 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 with an endless loop is 
> immortal (modulo unhandled panics).
> 
> -- 
> -j
> 
> 
> -- 
> 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 
> <mailto:golang-nuts+unsubscr...@googlegroups.com>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.
> 

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