summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pkg/sync/waitgroup.go14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/pkg/sync/waitgroup.go b/src/pkg/sync/waitgroup.go
index 2a0a94f40..22681115c 100644
--- a/src/pkg/sync/waitgroup.go
+++ b/src/pkg/sync/waitgroup.go
@@ -95,13 +95,6 @@ func (wg *WaitGroup) Wait() {
}
wg.m.Lock()
w := atomic.AddInt32(&wg.waiters, 1)
- if raceenabled && w == 1 {
- // Wait's must be synchronized with the first Add.
- // Need to model this is as a write to race with the read in Add.
- // As the consequence, can do the write only for the first waiter,
- // otherwise concurrent Wait's will race with each other.
- raceWrite(unsafe.Pointer(&wg.sema))
- }
// This code is racing with the unlocked path in Add above.
// The code above modifies counter and then reads waiters.
// We must modify waiters and then read counter (the opposite order)
@@ -119,6 +112,13 @@ func (wg *WaitGroup) Wait() {
}
return
}
+ if raceenabled && w == 1 {
+ // Wait must be synchronized with the first Add.
+ // Need to model this is as a write to race with the read in Add.
+ // As a consequence, can do the write only for the first waiter,
+ // otherwise concurrent Waits will race with each other.
+ raceWrite(unsafe.Pointer(&wg.sema))
+ }
if wg.sema == nil {
wg.sema = new(uint32)
}