-
Notifications
You must be signed in to change notification settings - Fork 0
/
gorout.go
39 lines (33 loc) · 812 Bytes
/
gorout.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
package main
import (
"fmt"
"runtime"
"time"
)
func l1() {
fmt.Println("l1 (goroutine) execution started")
for i := 0; i < 3; i++ {
fmt.Println("l1, i=", i)
}
fmt.Println("l1 execution finished")
}
func l2() {
fmt.Println("l2 (goroutine) execution started")
for i := 5; i < 16; i++ {
fmt.Println("l2, i=", i)
}
fmt.Println("l2 execution finished")
}
func main() {
fmt.Println("main execution started")
fmt.Println("No. of CPU's:", runtime.NumCPU())
fmt.Println("No. of Goroutines:", runtime.NumGoroutine())
fmt.Println("OS:", runtime.GOOS)
fmt.Println("Arch:", runtime.GOARCH)
fmt.Println("GOMAXPROCS:", runtime.GOMAXPROCS(0))
go l1()
fmt.Println("No. of Goroutines after go l1():", runtime.NumGoroutine())
l2()
time.Sleep(time.Second * 2)
fmt.Println("main execution stopped")
}