diff --git a/GetRuntimeAddresses/symbolyze/symbolyze.go b/GetRuntimeAddresses/symbolyze/symbolyze.go index 33cfee4..505eab3 100644 --- a/GetRuntimeAddresses/symbolyze/symbolyze.go +++ b/GetRuntimeAddresses/symbolyze/symbolyze.go @@ -122,7 +122,8 @@ func (S *Scanner) Run() error { proc.Close() - var wg sync.WaitGroup + var wg sync.WaitGroup // To be able to wait for all the observers to finish + for _, pinfo := range infos { var pid_s = pinfo.Name() @@ -134,22 +135,25 @@ func (S *Scanner) Run() error { } else if offset, found := S.searchSymbolIn(pid); !found { continue } else { - // Notify the observers. - for n, observer := range S.observers { - wg.Add(1) - go func() { - err = observer(pid, offset) - if err != nil { - S.Printf("S.observer[%d](%d, %d) error: %v", n, pid, offset, err) - // TODO: accumulate errors from all Observers. - } - wg.Done() - }() - } + // Call the observers with (pid, offset), in the + // background. + wg.Add(len(S.observers)) // Wait for this many goroutines + go func() { + for n, observer := range S.observers { + go func() { + err = observer(pid, offset) + if err != nil { + S.Printf("S.observer[%d](%d, %d) error: %v", n, pid, offset, err) + // TODO: accumulate errors from all Observers. + } + wg.Done() + }() + } + }() } } - wg.Wait() + wg.Wait() // Wait for all observers to finish return S.err }