I am new to Google Go (Golang). My question is related to this post What exactly does runtime.Gosched do?. The structure of code is as copied below. My question, is that when I change the number of processor in GOMAXPROCS, how do I verify how many processors it is running on. When I do 'top', it shows a.out process which consumes 100% or less resources even when GOMAXPROCS is more than 1. I would be grateful for your help.
package main
import (
"fmt"
"runtime"
"sync"
)
var wg sync.WaitGroup
func doTasks() {
fmt.Println(" Doing task ")
for ji := 1; ji < 100000000; ji++ {
for io := 1; io < 10; io++ {
//Some computations
}
}
runtime.Gosched()
wg.Done()
}
func main() {
wg.Add(1)
runtime.GOMAXPROCS(1) // or 2 or 4
go doTasks()
doTasks()
wg.Wait()
}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…