ryandotsmith / log-shuttle

New Repository: https://github.com/heroku/log-shuttle
https://github.com/heroku/log-shuttle
22 stars 6 forks source link

fix race #5

Closed kr closed 12 years ago

kr commented 12 years ago

Something could increment one of the counters after you read the old value and before you reset it to 0. If you instead atomically subtract the old value, then all events will still be counted.

hgmnz commented 12 years ago

I'm just learning Go, but:

AddUint64 atomically adds delta to *val and returns the new value.

So, that reads as if drops is not being updated at all (but with StoreUint64 it was), so the following Fprintf would output incorrect data. Or what am I misunderstanding here?

kr commented 12 years ago

Hmm, the description is ambiguous, but AddUint64 definitely modifies the value pointed at by the val parameter.

hgmnz commented 12 years ago

Oh yes, I see how it can mean that as well. Confirmed, too!

kr commented 12 years ago

You both might also find f3523a15a2e973db131b05e0806ba53176c84ec6 interesting.