Created
January 18, 2019 13:36
-
-
Save bschaeffer/bbea36c5f98de9b0995695070530cbfb to your computer and use it in GitHub Desktop.
WaitGroup example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"fmt" | |
"runtime" | |
"sync" | |
) | |
var wg sync.WaitGroup | |
func init() { | |
fmt.Println("OS\t\t", runtime.GOOS) | |
fmt.Println("ARCH\t\t", runtime.GOARCH) | |
fmt.Println("CPUs\t\t", runtime.NumCPU()) | |
fmt.Println("Goroutines\t", runtime.NumGoroutine()) | |
} | |
func main() { | |
wg.Add(1) | |
go foo() | |
bar() | |
wg.Wait() | |
} | |
func foo() { | |
for i := 0; i < 10; i++ { | |
fmt.Println("foo:", i) | |
} | |
wg.Done() | |
} | |
func bar() { | |
for i := 0; i < 10; i++ { | |
fmt.Println("bar:", i) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment