3 ms·
Has anyone tried the new scheduler? Does this still block forever? package main import "time" func main() { go func(){ for {} }() time.Sleep(time.Milli
by drsintoma 13y ago
Has anyone tried the new scheduler?
Does this still block forever?
package main
import "time"
func main() {
go func(){
for {}
}()
time.Sleep(time.Millisecond)
}
- drsintoma 13y agoOk, I just tried it. It still does.
- Skinney 13y agoThat will still block forever. If you include a function call in the loop though, it won't.
- ominous_prime 13y agowhile they have added some preemption to the scheduler, go is still generally cooperative multitasking. I believe function calls are also schedule points now. If you have a cpu-intensive loop you want to yield from at certain points, stick a runtime.GoSched in there. Having a busy-loop in your code is going to mess things up, and is usually a bug anyway.
- masklinn 13y ago> Having a busy-loop in your code is going to mess things up, and is usually a bug anyway. A busy loop is a sufficient way to emulate a heavy computation (e.g. applying effects to image files or compressing data) when it's not optimized out.