September 2017
Intermediate to advanced
466 pages
9h 33m
English
This time, the number of goroutines that will be created will be given as a command-line argument: the name of the program will be dynamicGR.go and will be presented in four parts.
The first part of dynamicGR.go is the following:
package main import ( "fmt" "os" "path/filepath" "strconv" "sync" )
The second part of dynamicGR.go contains the following Go code:
func main() {
if len(os.Args) != 2 {
fmt.Printf("usage: %s integer\n",filepath.Base(os.Args[0]))
os.Exit(1)
}
numGR, _ := strconv.ParseInt(os.Args[1], 10, 64)
fmt.Printf("Going to create %d goroutines.\n", numGR)
var waitGroup sync.WaitGroup
var i int64
for i = 0; i < numGR; i++ {
waitGroup.Add(1)
As you can see, the waitGroup.Add(1) statement ...
Read now
Unlock full access