The problem is I get
about >1ms delay when I create one hundred/thousand gorountine.
func main() {
for i := 0; i < 100; i++ { // or use 1000
go func() { testWaitRoutine() }()
}
time.Sleep(10 * time.Second)
}
func testWaitRoutine() {
channl := make(chan int, 1)
go func() {
channl <- time.Now().Nanosecond()
time.Sleep(3 * time.Second)
channl <- time.Now().Nanosecond()
}()
_, secondTime := <-channl, <-channl
nowTime := time.Now().Nanosecond()
delay := nowTime - secondTime
println(delay)
}
OUTPUT show there are very few result count of microseconds and milliseconds delay, such as:
...
3000
338000
2000
...
1000
1000
72000
1000
...
2000
2000
1185000
1000
1000
...
Hardware: Both of MBP(2017) and Windows 10 have this phenomenon.
[Question]
Why will gorountine give a larger delay result sometimes than a stable delay number? What’s the underlay implementation causing?