News for hackers. Stuff that matters.
Re:Why you can have millions of goroutines but only thousand... by denormalfloat on Tuesday October 09, 2018 @01:10AM (#18173474)
Go's scheduler is not preemptive, which means that sometimes Goroutines can hog the processor. If loops don't contain function calls, or allocate memory, or other preemption points, they can prevent other goroutines from running. A simple example is:

    package main
    func main() {
      go println("I ran")
      for {}
    }
If you run with:

    GOMAXPROCS=1 go run main.go
It will never print the statement. This doesn't come up frequently in practice, but Linux does not suffer from this case.
Re:Why you can have millions of goroutines but only thousand... by twtw on Tuesday October 09, 2018 @02:09AM (#18173671)
I heard Go got a preemptive scheduler recently.

EDIT: https://github.com/golang/go/issues/24543

Re:Why you can have millions of goroutines but only thousand... by the_clarence on Tuesday October 09, 2018 @04:02AM (#18174099)
This just happened to me. I wanted to run a goroutine and then not exit the program, so I ran an empty for loop and it didn’t work. Would a for{ continue } have work?
Re:Why you can have millions of goroutines but only thousand... by majewsky on Tuesday October 09, 2018 @05:12AM (#18174378)
`for { continue }` is semantically equivalent to `for {}` since the closing bracket of the loop block implies a `continue`.

As a sibling correctly notes, `select {}` is what you want to do instead. You need to do something that can block the goroutine in such a way that control returns to the scheduler. Selecting is one of those ways.

Re:Why you can have millions of goroutines but only thousand... by grose on Tuesday October 09, 2018 @04:55AM (#18174296)
You can use select{} to block forever and yield the goroutine.
Re:Why you can have millions of goroutines but only thousand... by the_clarence on Tuesday October 09, 2018 @12:28PM (#18177326)
Yield?
Re:Why you can have millions of goroutines but only thousand... by devxpy on Tuesday October 09, 2018 @01:55AM (#18173629)
Interesting find.