Make it run in parallel
While our goroutines were running concurrently, they were not running inparallel. When you do not tell Go anything there can only be one goroutinerunning at a time. With runtime.GOMAXPROCS(n)
you can set the number ofgoroutines that can run in parallel. From the documentation:
GOMAXPROCS sets the maximum number of CPUs that can be executingsimultaneously and returns the previous setting. If n < 1, it does notchange the current setting. This call will go away when the schedulerimproves.
If you do not want to change any source code you can also set an environmentvariable GOMAXPROCS
to the desired value.
Note that the above discussion relates to older versions of Go. Fromversion 1.5 and above, GOMAXPROCS
defaults to the number of CPUcores[go_1_5_release_notes].