From ecf93839f8c6b55de46b9dd20dfb958fb8a02c0d Mon Sep 17 00:00:00 2001 From: Oliver Tonnhofer Date: Wed, 7 Dec 2016 13:49:58 +0100 Subject: [PATCH] fix data race in barrier for first way|relation callbacks --- parser/pbf/process.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/parser/pbf/process.go b/parser/pbf/process.go index 0569b1d..16c07f3 100644 --- a/parser/pbf/process.go +++ b/parser/pbf/process.go @@ -3,6 +3,7 @@ package pbf import ( "runtime" "sync" + "sync/atomic" "github.com/omniscale/imposm3/element" ) @@ -140,7 +141,7 @@ func (p *Parser) parseBlock(pos block) { // doneWait() blocks until the callback returns. doneWait() does not // block after all goroutines were blocked once. type barrier struct { - synced bool + synced int32 wg sync.WaitGroup once sync.Once callbackWg sync.WaitGroup @@ -158,7 +159,7 @@ func (s *barrier) add(delta int) { } func (s *barrier) doneWait() { - if s.synced { + if atomic.LoadInt32(&s.synced) == 1 { return } s.wg.Done() @@ -169,6 +170,6 @@ func (s *barrier) doneWait() { func (s *barrier) call() { s.callback() - s.synced = true + atomic.StoreInt32(&s.synced, 1) s.callbackWg.Done() }