I want to run multiple Go routines. I want them to all start up the same time. I added another sync waitGroup and added a wait inside the start of the go routine. This however did not work to have all the go routine start at the same time. What should I do in order to have a number of go routines to start exactly at the same time?
package main
import (
"flag"
"fmt"
"sync"
"time"
)
func main() {
var wg sync.WaitGroup
routines := flag.Int("runs", 100, "routines running")
flag.Parse()
wg.Add(*routines)
for i := 0; i < *routines; i++ {
go func() {
defer wg.Done()
t := time.Now()
fmt.Printf("%s
", t)
}()
}
fmt.Println("Waiting To Finish")
wg.Wait()