Last active
July 8, 2020 12:44
-
-
Save d-led/066b7a9b8ce52e345e62212716daa02a to your computer and use it in GitHub Desktop.
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" | |
"time" | |
) | |
func main() { | |
go tick() | |
count := 1 | |
for { | |
go spin() | |
fmt.Printf("Started task %v\n", count) | |
time.Sleep(2 * time.Second) | |
count++ | |
} | |
runtime.Goexit() | |
} | |
func tick() { | |
i := 0 | |
for { | |
fmt.Printf("Tick %v\n", i) | |
time.Sleep(1 * time.Second) | |
i++ | |
} | |
} | |
func spin() { | |
i := 0 | |
for { | |
i++ | |
// runtime.Gosched() // yield... | |
} | |
} |
to give up control gracefully
if i%1000000000 == 0 {
fmt.Printf("Task: %v\n", id)
}
seems not to be the case anymore: go1.14.3
...
Started task 50
Tick 97
Tick 98
Started task 51
Tick 99
Tick 100
Started task 52
Tick 101
Tick 102
Started task 53
Tick 103
Tick 104
Started task 54
Tick 105
Tick 106
Started task 55
Tick 107
Tick 108
Started task 56
Tick 109
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see how the scheduler threads are exhausted