From 609274326bb365ee13df8cfb9b78705eca1a286a Mon Sep 17 00:00:00 2001 From: Reinhard Koehn Date: Tue, 4 Feb 2020 22:17:27 +0100 Subject: [PATCH] Ensure 64bit alignment on 32bit builds for atomics (#3065) Keep elements that are used with atomic.* functions as first element of struct because it guarantees 64bit alignment on 32 bit machines. atomic.* functions crash if operand is not aligned at 64bit. See https://github.com/golang/go/issues/599 --- cmd/parallel-manager.go | 9 ++++++--- cmd/status.go | 14 ++++++++++---- 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/cmd/parallel-manager.go b/cmd/parallel-manager.go index c017cbd9..f7955537 100644 --- a/cmd/parallel-manager.go +++ b/cmd/parallel-manager.go @@ -36,15 +36,18 @@ const ( // ParallelManager - helps manage parallel workers to run tasks type ParallelManager struct { + // Calculate sent bytes. + // Keep this as first element of struct because it guarantees 64bit + // alignment on 32 bit machines. atomic.* functions crash if operand is not + // aligned at 64bit. See https://github.com/golang/go/issues/599 + sentBytes int64 + // Synchronize workers wg *sync.WaitGroup // Current threads number workersNum uint32 - // Calculate sent bytes. - sentBytes int64 - // Channel to receive tasks to run queueCh chan func() URLs // Channel to send back results diff --git a/cmd/status.go b/cmd/status.go index f76bffc2..79494c4f 100644 --- a/cmd/status.go +++ b/cmd/status.go @@ -59,9 +59,12 @@ func NewQuietStatus(hook io.Reader) Status { // QuietStatus will only show the progress and summary type QuietStatus struct { - *accounter - hook io.Reader + // Keep this as first element of struct because it guarantees 64bit + // alignment on 32 bit machines. atomic.* functions crash if operand is not + // aligned at 64bit. See https://github.com/golang/go/issues/599 counts int64 + *accounter + hook io.Reader } // Read implements the io.Reader interface @@ -151,9 +154,12 @@ func NewProgressStatus(hook io.Reader) Status { // ProgressStatus shows a progressbar type ProgressStatus struct { - *progressBar - hook io.Reader + // Keep this as first element of struct because it guarantees 64bit + // alignment on 32 bit machines. atomic.* functions crash if operand is not + // aligned at 64bit. See https://github.com/golang/go/issues/599 counts int64 + *progressBar + hook io.Reader } // Read implements the io.Reader interface