if you get into the fmt.println, you will see the output device is os.Stdout, any println call will direct output into it nodelay
在 2017年1月21日星期六 UTC+8上午11:34:09,Rodolfo Azevedo写道: > > Hi all, > > I have a question, interesting: > > Why the executes is diferente in these both situations? > > Execute A: > > [11:19] > ```package main > > import ( > "fmt" > "sync" > "time" > ) > > var wg sync.WaitGroup > > func A() { > > time.Sleep(time.Second * 5) > fmt.Println("Função A") > wg.Done() > > } > > func B() { > > fmt.Println("Função B") > wg.Done() > > } > > func C() { > > time.Sleep(time.Second * 5) > fmt.Println("Função C") > wg.Done() > > } > > func main() { > > wg.Add(3) > defer wg.Wait() > > go A() > go B() > go C() > > } > ``` > > Execute B: > > [11:20] > ```package main > > import ( > "fmt" > "sync" > "time" > ) > > var wg sync.WaitGroup > > func A() { > > fmt.Println("Função A") > time.Sleep(time.Second * 5) > wg.Done() > > } > > func B() { > > fmt.Println("Função B") > wg.Done() > > } > > func C() { > > fmt.Println("Função C") > time.Sleep(time.Second * 5) > wg.Done() > > } > > func main() { > > wg.Add(3) > defer wg.Wait() > > go A() > go B() > go C() > > } > ``` > > [11:21] > In execute A, function A and C wait 5 seconds, then prints output. In > execute B no, all the prints executes without respecting time.Sleep. > Someone can explain why? > > [11:22] > I only change the order of time.Sleep in functions A and C. > -- 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.