GOMAXPROCS
What will be printed when the code below is executed?Will it be different when line A is changed to GOMAXPROCS=2
?
package main
import (
"fmt"
"runtime"
"sync"
)
func main() {
const GOMAXPROCS = 4 //A
runtime.GOMAXPROCS(GOMAXPROCS)
var wg sync.WaitGroup
wg.Add(2)
go func() {
defer wg.Done()
for char := 0; char < 26; char++ {
fmt.Printf("%c ", 'A'+char)
}
}()
go func() {
defer wg.Done()
for char := 0; char < 26; char++ {
fmt.Printf("%c ", 'a'+char)
}
}()
wg.Wait()
}
Answer
When GOMAXPROCS=1, the printed output will be a-zA-Z.
When GOMAXPROCS=2, a-z will be mixed with A-Z.