mirror of
https://github.com/crazybber/awesome-patterns.git
synced 2024-11-22 12:46:03 +03:00
list thread
This commit is contained in:
parent
c842e3dc10
commit
10e9ef931b
@ -4,6 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"runtime"
|
"runtime"
|
||||||
|
"strconv"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -39,17 +40,24 @@ func main() {
|
|||||||
go outputText(hello)
|
go outputText(hello)
|
||||||
go outputText(world)
|
go outputText(world)
|
||||||
goSched()
|
goSched()
|
||||||
|
runtime.GOMAXPROCS(2)
|
||||||
|
fmt.Printf("%d thread(s) available to Go.", listThreads())
|
||||||
}
|
}
|
||||||
|
|
||||||
func goSched() {
|
func goSched() {
|
||||||
iterations := 10
|
iterations := 10
|
||||||
for i := 0; i <= iterations; i++ {
|
for i := 0; i <= iterations; i++ {
|
||||||
go showNumber(i)
|
showNumber(i)
|
||||||
}
|
}
|
||||||
runtime.Gosched()
|
|
||||||
fmt.Println("Goodbye!")
|
fmt.Println("Goodbye!")
|
||||||
}
|
}
|
||||||
|
|
||||||
func showNumber(num int) {
|
func showNumber(num int) {
|
||||||
fmt.Println(num)
|
tstamp := strconv.FormatInt(time.Now().UnixNano(), 10)
|
||||||
|
fmt.Println(num, tstamp)
|
||||||
|
}
|
||||||
|
|
||||||
|
func listThreads() int {
|
||||||
|
threads := runtime.GOMAXPROCS(0)
|
||||||
|
return threads
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user