If I understood correctly, then the concurrent collections create a snapshot as a source for the Enumerator
used in a foreach
loop, which requires locking.
Do they cache the snapshots or lock every time? Does this have a potential performance impact? I'm sceptical about micro-measurements, because they so easily lead to false conclusions and am trying to understand the inner workings.
Thanks!
No, it doesn't appear to cache. Here's the code from
ConcurrentBag<T>
: