func main() {// Allocate 1 logical processors for the scheduler to useruntime.GOMAXPROCS(1)// runtime.GOMAXPROCS(runtime.NumCPU())var wg sync.WaitGroupwg.Add(2)fmt.Println("Start Goroutines")go func() {defer wg.Done()for count := 0; count < 3; count++ {for char := 'a'; char < 'a'+26; char++ {fmt.Printf("%c ", char)}fmt.Println()}}()go func() {defer wg.Done()for count := 0; count < 3; count++ {for char := 'A'; char < 'A'+26; char++ {fmt.Printf("%c ", char)}fmt.Println()}}()wg.Wait()fmt.Println("Waiting To Finish")fmt.Println("\nTerminating Program")}
A WaitGroup is a counting semaphore that can be used to maintain a record of running goroutines.
