I have this basic go program that prints to the console and calls 2 goroutines
package main
import (
"fmt"
"time"
)
func f(from string) {
for i := 0; i < 3; i++ {
fmt.Println(from, ":", i)
}
}
func main() {
f("hello")
go f("foo")
go f("bar")
time.Sleep(time.Second)
}
The output is as follows -- and I'm wondering why "bar" is printed before "foo" -- what determines the execution order of the goroutines?
hello : 0
hello : 1
hello : 2
bar : 0
bar : 1
bar : 2
foo : 0
foo : 1
foo : 2