On Jun 28, 12:56 pm, c...@dynamicweb.dk wrote:
> I agree with you to a degree, setting up memory barriers or using low-
> lock techniques, is not an option in my opinion, to complex and
> unreadable. But the code construct above is relatively simple and
> readable, so if it works, it would be great.
It's fairly simple and in some senses readable (although not as simple
or readable as without the double-checking, IMO) but the problem is
that it's very hard to reason about, especially without the code for
ContainsKey. The fact that it's not obvious whether or not it's thread-
safe is a big knock to its readability, IMO.
> There are lots of posts and blogs concerning the "right" singleton
> implementation, and the thread safety of generic collections, but, no
> clear answers... So the question is also interesting from an
> theoretically point of view,
>From an academic point of view it's certainly interesting, although
I'm afraid I have no answers.
> and the implementation of dictionary<,>,
> would be interesting to se! Is it available somewhere?
Well, there's Reflector, and there may be an implementation in Rotor,
but MS doesn't publish the source code to the .NET framework
libraries, unfortunately.
Jon