On Sun, Nov 27, 2016 at 10:25 PM, Jesper Louis Andersen <jesper.louis.ander...@gmail.com> wrote: > On Fri, Nov 25, 2016 at 10:51 PM Dave Cheney <d...@cheney.net> wrote: >> >> >> Yes, goroutine switching occurs a known points; effectively where the >> goroutine is blocked from proceeding; sending and receiving on channels (if >> they are full/empty respectively), trying to acquire a locked mutex, and >> performing IO. These operations happen frequently in a program that >> interacts with others so things more or less work out. >> > I was of the impression Go checks on function calls nowadays. Since you have > to check the stack anyway, you can always piggyback on that routine if you > want the system to schedule out the goroutine.
Yes, that is correct, the runtime has its own goroutine called sysmon which waits up to 10ms and then sets the stack size to the longest running goroutine to a negative number. The next time the goroutine executes a function call it will trap into the stack growth slow path and be preempted. > > Only checking on points-of-communication could lead to worse latency because > a non-communicating goroutine is then able to tie up a processing core > indefinitely, and delay garbage collection. Yup, the problem with a spinning goroutine blocking the STW safe point has been known for several releases. The mechanism above appears to limit the worst case to 20ms in my testing. > Not checking inside for-loops puts the onus on the programmer to break such > loops via function calls, but this is a far easier thing to handle from a > programmer perspective when needed, and when not needed it could be argued > it needlessly slows down the program. David Chase has adding a check on the loop edge as an experiment, it comes at about a 15% cost. > -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.