-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconcurency.go
46 lines (36 loc) · 853 Bytes
/
concurency.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package main
import (
"fmt"
"runtime"
"sync"
)
var wg sync.WaitGroup
func main() {
fmt.Println("OS\t", runtime.GOOS)
fmt.Println("ARCH\t", runtime.GOARCH)
fmt.Println("CPUs\t", runtime.NumCPU())
fmt.Println("Go Routines\t", runtime.NumGoroutine())
fmt.Println("Version\t", runtime.Version())
// fmt.Println("Memory Profile\t", runtime.ReadMemStats(&runtime.MemStats))
fmt.Println("------------------------------")
// foo()
// bar()
wg.Add(1)
go foo()
fmt.Println("Waiting List Go Routines ", runtime.NumGoroutine())
wg.Wait()
wg.Add(1)
go bar()
fmt.Println("Waiting List Go Routines ", runtime.NumGoroutine())
wg.Wait()
fmt.Println("Waiting List Go Routines ", runtime.NumGoroutine())
fmt.Println("We are Done!!:)")
}
func foo() {
fmt.Println("I am foo")
wg.Done()
}
func bar() {
fmt.Println("I am bar")
wg.Done()
}