GOMAXPROCS

What will be printed when the code below is executed?Will it be different when line A is changed to GOMAXPROCS=2 ?

  1. package main
  2. import (
  3. "fmt"
  4. "runtime"
  5. "sync"
  6. )
  7. func main() {
  8. const GOMAXPROCS = 4 //A
  9. runtime.GOMAXPROCS(GOMAXPROCS)
  10. var wg sync.WaitGroup
  11. wg.Add(2)
  12. go func() {
  13. defer wg.Done()
  14. for char := 0; char < 26; char++ {
  15. fmt.Printf("%c ", 'A'+char)
  16. }
  17. }()
  18. go func() {
  19. defer wg.Done()
  20. for char := 0; char < 26; char++ {
  21. fmt.Printf("%c ", 'a'+char)
  22. }
  23. }()
  24. wg.Wait()
  25. }

Answer

  1. When GOMAXPROCS=1, the printed output will be a-zA-Z.
  2. When GOMAXPROCS=2, a-z will be mixed with A-Z.