I am new to Go language programming and learning it step by step.
While practicing it, I found random behavior of goroutines.
If I call goroutine (function having sleep of 1 second), some times it completed successfully and some times it doesn't:
package main
import (
"fmt"
"time"
)
func t(i int) {
fmt.Println("In func t")
time.Sleep(1)
}
func t1(i int) {
fmt.Println("In func t1")
time.Sleep(1)
}
func main() {
fmt.Println("Hello Good Morning")
go t(1)
t1(2)
time.Sleep(5)
fmt.Println("End of func main")
}
O/p 1 :
Hello Good Morning
In func t1
In func t
End of func main
O/p 2 :
Hello Good Morning
In func t1
End of func main
Could someone explain why goroutine is not guaranteeing the execution of that goroutine function call.