Skip to content

Commit

Permalink
progress: fix race-condition while reading value
Browse files Browse the repository at this point in the history
  • Loading branch information
jedib0t committed Jun 10, 2019
1 parent f5c9bfa commit 216d1ef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 0 deletions.
2 changes: 2 additions & 0 deletions progress/progress.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,11 @@ func (p *Progress) AppendTracker(t *Tracker) {
p.trackersInQueueMutex.Lock()
p.trackersInQueue = append(p.trackersInQueue, t)
p.trackersInQueueMutex.Unlock()
p.overallTracker.mutex.Lock()
if p.overallTracker.Total < int64(p.Length())*100 {
p.overallTracker.Total = int64(p.Length()) * 100
}
p.overallTracker.mutex.Unlock()
p.overallTrackerMutex.Unlock()
}

Expand Down
2 changes: 2 additions & 0 deletions progress/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,9 @@ func (p *Progress) renderTrackerStats(out *strings.Builder, t *Tracker, hint ren
var outStats strings.Builder
outStats.WriteString(" [")
if !hint.hideValue {
t.mutex.Lock()
outStats.WriteString(p.style.Colors.Value.Sprint(t.Units.Sprint(t.value)))
t.mutex.Unlock()
}
if !hint.hideValue && !hint.hideTime {
outStats.WriteString(" in ")
Expand Down

0 comments on commit 216d1ef

Please sign in to comment.