It's only polite to let other's know when cross-posting questions, to avoid 
wasting time.
https://stackoverflow.com/questions/44657084/why-main-goroutine-always-be-the-second-to-be-invoked

The answer and comments there seems to cover most aspects of the behavior 
you're seeing. 


On Tuesday, June 20, 2017 at 1:10:34 PM UTC-4, Jun An wrote:
>
> here is the code, why can't main goroutine be a little quick and exit then 
> discard another goroutine?
>
> package main
>
> import (
> "sync"
> "time"
> )
>
> func main() {
> var wg sync.WaitGroup
>
> wg.Add(1)
>
> go func() {
> wg.Wait()
> println("wait exit")
> }()
>
> go func() {
> time.Sleep(time.Second)
> wg.Done()
> }()
>
> wg.Wait()
> println("main exit")
> }
>
>
>
>

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