From 11b5b81f3e47c4c91bc074f58d04ed63589b7562 Mon Sep 17 00:00:00 2001 From: WeebDataHoarder <57538841+WeebDataHoarder@users.noreply.github.com> Date: Thu, 20 Jan 2022 17:51:36 +0100 Subject: [PATCH] Prevent addition stalling --- SynchRoGazer.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/SynchRoGazer.go b/SynchRoGazer.go index e8010a2..ce75654 100644 --- a/SynchRoGazer.go +++ b/SynchRoGazer.go @@ -235,6 +235,8 @@ func main() { var taskCount int64 + var entries int64 + scanner := bufio.NewScanner(os.Stdin) defer os.Stdin.Close() @@ -261,6 +263,7 @@ func main() { defer atomic.AddInt64(&taskCount, -1) for scanner.Scan() { path := scanner.Text() + atomic.AddInt64(&entries, 1) atomic.AddInt64(&taskCount, 1) go func() { @@ -279,8 +282,11 @@ func main() { //Already print before finishing, use atomic ints instead of a WaitGroup for atomic.LoadInt64(&taskCount) > 0 { - result := <-resultChannel - PrintHashFileResult(&result, *outputFormat, pgSettings) + if atomic.LoadInt64(&entries) > 0 { + atomic.AddInt64(&entries, -1) + result := <-resultChannel + PrintHashFileResult(&result, *outputFormat, pgSettings) + } } close(resultChannel)