From c0a0e0bdc193622ec44c9040c816008b6083809d Mon Sep 17 00:00:00 2001 From: Derek Parker Date: Sat, 5 Sep 2015 18:29:33 -0500 Subject: [PATCH] proc/proc: Fix OSX hangs in highly parallel programs `next` would hang in highly parallel programs, causing test flickers and unexpected behavior. This patch fixes it by examining all stopped threads whenever Delve gets a notification, instead of just the thread that caused the stop. --- proc/proc.go | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/proc/proc.go b/proc/proc.go index 46023715..fa5146ff 100644 --- a/proc/proc.go +++ b/proc/proc.go @@ -309,28 +309,33 @@ func (dbp *Process) next() (err error) { } for { - th, err := dbp.trapWait(-1) + _, err := dbp.trapWait(-1) if err != nil { return err } - tg, err := th.GetG() - if err != nil { - return err - } - // Make sure we're on the same goroutine, unless it has exited. - if tg.Id == g.Id || goroutineExiting { - // Check to see if the goroutine has switched to another - // thread, if so make it the current thread. - if err := dbp.SwitchThread(th.Id); err != nil { + for _, th := range dbp.Threads { + if !th.Stopped() { + continue + } + tg, err := th.GetG() + if err != nil { + return err + } + // Make sure we're on the same goroutine, unless it has exited. + if tg.Id == g.Id || goroutineExiting { + // Check to see if the goroutine has switched to another + // thread, if so make it the current thread. + if err := dbp.SwitchThread(th.Id); err != nil { + return err + } + return nil + } + // This thread was not running our goroutine. + // We continue it since our goroutine could + // potentially be on this threads queue. + if err = th.Continue(); err != nil { return err } - return nil - } - // This thread was not running our goroutine. - // We continue it since our goroutine could - // potentially be on this threads queue. - if err = th.Continue(); err != nil { - return err } } } -- GitLab