Ich bin neu in der Go Sprache und Lernen hier: https://tour.golang.org/concurrency/1A Tour of Go Beispiel auf Goroutines Gleichzeitigkeit
Wenn ich laufe https://play.golang.org/p/9JvbtSuv5o das Ergebnis:
world
hello
hello
sync.WaitGroup
So Hinzugefügt: https://play.golang.org/p/vjdhnDssGk
package main
import (
"fmt"
"sync"
"time"
)
var w sync.WaitGroup
func say(s string) {
for i := 0; i < 2; i++ {
time.Sleep(100 * time.Millisecond)
fmt.Println(s)
}
w.Done()
}
func main() {
w.Add(1)
go say("world")
say("hello")
w.Wait()
}
Aber das Ergebnis ist gleich:
world
hello
hello
Was ist falsch an meinem Code?
Bitte helfen,
Vielen Dank für Ihre Hilfe.