Исходники и презентации
This commit is contained in:
25
lessons/goroutines_and_scheduler/async_preemptible/main.go
Normal file
25
lessons/goroutines_and_scheduler/async_preemptible/main.go
Normal file
@ -0,0 +1,25 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"log"
|
||||
"runtime"
|
||||
)
|
||||
|
||||
func infiniteLoop(str string) {
|
||||
for {
|
||||
log.Println(str)
|
||||
}
|
||||
}
|
||||
|
||||
func loop(str string) {
|
||||
for i := 0; i < 5; i++ {
|
||||
runtime.Gosched()
|
||||
log.Println(str)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
runtime.GOMAXPROCS(1)
|
||||
go infiniteLoop("infinite_loop")
|
||||
loop("loop")
|
||||
}
|
||||
Reference in New Issue
Block a user