So, I am testing Golang. I understand fmt.Println is not thread safe. So, I was trying out sync.Mutex. The following is the program:
func threder(mux *Mutex, i int) {
mux.Lock()
fmt.Println("I am thread: ", i)
mux.Unlock()
return
}
func main() {
m := &Mutex{}
for i := 0; i < 300; i++ {
go threder(m, i)
}
}
I am expecting 300 lines of output. But, I am getting 80-90 lines. Where am I wrong?