Recognos / Metrics.NET

The Metrics.NET library provides a way of instrumenting applications with custom metrics (timers, histograms, counters etc) that can be reported in various ways and can provide insights on what is happening inside a running application.
Apache License 2.0
639 stars 110 forks source link

Is UniformReservoir thread safe? #64

Open LeonidVasilyev opened 7 years ago

LeonidVasilyev commented 7 years ago

Current version of UniformReservoir stores values in array of UserValueWrapper. UserValueWrapper is a value type that consists of two fields. One of them is of type long and the other one is of type string. UserValueWrapper is larger that any native word. UniformReservoir Update() stores new values without locking or interlocked operations. GetSnapshot doesn't use locking or interlocked operation to copy array of values either. As I see it, UserValueWrapper instances writes and reads aren't atomic and because of that torn values may end up in reservoir or snapshot (see I.12.6.6 Atomic reads and writes section of ECMA-335 Common Language Infrastructure (CLI)). However, I wasn't able to write a test case that produces torn values.