Skip to content

Commit

Permalink
Remove runtime.Gosched loops, source issue golang/go#10958 is resolved.
Browse files Browse the repository at this point in the history
  • Loading branch information
200sc committed Jun 6, 2020
1 parent 7becfab commit 36429df
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 26 deletions.
15 changes: 0 additions & 15 deletions event/resolve.go
Original file line number Diff line number Diff line change
@@ -1,29 +1,14 @@
package event

import (
"runtime"
)

// ResolvePending is a contant loop that tracks slices of bind or unbind calls
// and resolves them individually such that they don't break the bus
// Todo: this should be a function on the event bus itself, and should have a better name
// If you ask "Why does this not use select over channels, share memory by communicating",
// the answer is we tried, and it was cripplingly slow.
func (eb *Bus) ResolvePending() {
eb.init.Do(func() {
schedCt := 0
for {
eb.Flush()

// This is a tight loop that can cause a pseudo-deadlock
// by refusing to release control to the go scheduler.
// This code prevents this from happening.
// See https://github.com/golang/go/issues/10958
schedCt++
if schedCt > 1000 {
schedCt = 0
runtime.Gosched()
}
}
})
}
Expand Down
11 changes: 0 additions & 11 deletions inputLoop.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package oak

import (
"runtime"

"github.com/oakmound/oak/v2/event"

"github.com/oakmound/oak/v2/dlog"
Expand Down Expand Up @@ -31,7 +29,6 @@ func inputLoop() {
// Standard input
eventFn = windowControl.NextEvent
}
schedCt := 0
for {
switch e := eventFn().(type) {
// We only currently respond to death lifecycle events.
Expand Down Expand Up @@ -123,13 +120,5 @@ func inputLoop() {
//dlog.Verb("Got size event", e)
ChangeWindow(e.WidthPx, e.HeightPx)
}
// This loop can be tight enough that the go scheduler never gets
// a chance to take control from this thread. This is a hack that
// solves that.
schedCt++
if schedCt > 1000 {
schedCt = 0
runtime.Gosched()
}
}
}

0 comments on commit 36429df

Please sign in to comment.