Encounter a confused situation :
let's say we have a for { select }
function which is written in Go.
Here the code below:
package main
//import "fmt"
func main(){
for {
select {
default:
_=1 1. first situation
// fmt.Sprint("aa") 2. second situation
}
}
}
while in the first situation the cup usage shows below: in the second situation the cpu usage shows below:
I guess something happened in fmt.Println .
May be related to the mechanism of Go's fmt realization?
Not quite sure how it happens by using all the CPUs?
Thanks in advance !
My guess: In the first statement go's scheduler can't work. Go's scheduler is semi cooperative, and only works at certain points. Like function calls for example.
In an infinite loop with no function calls the scheduler has no chance to kick in..