Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions generator/count/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,13 @@ func (t *Tracker) Acquire() bool {
}
if t.remaining.CompareAndSwap(cur, cur-1) {
if cur-1 == 0 {
// Guard doneOnce/doneCh with mu so this terminal-permit close
// is ordered against Reset(), which reassigns them under mu.
// The lock is taken only on the last permit, so the common
// acquire path stays lock-free (atomic CAS only).
t.mu.Lock()
t.doneOnce.Do(func() { close(t.doneCh) })
t.mu.Unlock()
}
return true
}
Expand Down
Loading