You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// AddTime adds a time.Duration to Tachymeter.func (m*Tachymeter) AddTime(t time.Duration) {
m.Times[(atomic.AddUint64(&m.Count, 1)-1)%m.Size] =t
}
m.Count is atomically incremented, but accessing m.Times slice isn't. As such, calling AddTime() from multiple goroutines does triggers a data race. The higher the number of goroutines and/or the smaller the value of m.Size, the higher the probability of a data race occurring.
The text was updated successfully, but these errors were encountered:
arl
added a commit
to develersrl/tachymeter
that referenced
this issue
Sep 13, 2018
There was a data race in `Tachymeter.AddTime`.
`m.Count` was atomically incremented, but accessing `m.Times` slice
wasn't. As such, calling `AddTime()` from multiple goroutines triggered
a data race. The higher the number of goroutines and/or the smaller
the value of `m.Size`, the higher the probability of a data race
occurring.
Fixesjamiealquiza#43
Add -race in travis-ci script
Also, did you confirm this in any way that you could share? Calling the AddUint64 from multiple goroutines ensures unique index numbers. You could however write fast enough with a very small m.Times slice that a goroutine that's wrapped around (since this is a sliding window) writes to an index from the previous window. I haven't thought it through yet whether this has undesired consequences.
There is a data race in
Tachymeter.AddTime
m.Count
is atomically incremented, but accessingm.Times
slice isn't. As such, callingAddTime()
from multiple goroutines does triggers a data race. The higher the number of goroutines and/or the smaller the value ofm.Size
, the higher the probability of a data race occurring.The text was updated successfully, but these errors were encountered: