I was testing how a blocking operation works on Go, and how it deprives other go-routines from having processor share, so I did that test:
package main
import (
"fmt"
"runtime"
"time"
)
func test2() {
for i := 1; ; i++ {
fmt.Println(i, time.Now())
}
}
func test() {
a := 100
for i := 1; i < 1000; i++ {
a = i*100/i + a
fmt.Println("value: " , a )
}
}
func main() {
runtime.GOMAXPROCS(1)
go test2()
for {
test()
}
}
As you can see in the example, first line of main() I'm setting Go to use a single core and a never ending task runs on, so that it blocks any other process, though I see results I didn't expect,I found out that both test and test2 are running, each having it's time share (a larger time share per process that's longer than if I set the GOMAXPROCS to higher values). This is the output:
https://gist.github.com/anonymous/b3634be74d30fd36f552
How can I explain this?
P.S. I'm using Go version 1.5.3
Update
I made a little change by setting GOMAXPROC to 2, removed fmt.Println("value: " , a )
from test function, now, the program runs test2 for some time and, the test
function takes over and nothing else run!!