Hacker News new | ask | show | jobs
by jhoechtl 2311 days ago
> Goroutines are now asynchronously preemptible. As a result, loops without function calls no longer potentially deadlock the scheduler or significantly delay garbage collection.

What does that mean in practice? Can I perform expensive calculations in parallel exhausting all cores?

3 comments

This means that the threads can't be blocked forever. The way Go scheduler work is to check during function calls if the current goroutine has executed for some period of time, after that the scheduler will remove the goroutine from the thread and open space for other goroutines to execute. But if you're doing a loop without function calls, imagine a for {}, in this case, the thread will be locked forever. Now with 1.14, this don't happen anymore. In my opinion the expected result will be better tail latencies.
It means the following program will happily exit now.

  package main
  
  import (
    "time"
    "runtime"
  )
  
  func main(){
    for i := runtime.NumCPU(); i > 0; i-- {
      go func() {
        for {}
      }()
    }
    time.Sleep(time.Second)
    println("bye")
  }
Go has supported running goroutines in parallel since before 1.0, and it’s been the default behaviour since version 1.5, released in 2015.