Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

7
  • I prefer to use the encapsulated property init Commented Mar 16, 2011 at 13:41
  • I've seen this mentioned multiple times, and usually linking to a page such as Massif links here, that complains about Java. This post isn't about Java, though. I've seen no real evidence that double-check locking does not work in .NET. I'd be interested in seeing it, if it exists. Commented Mar 16, 2011 at 13:44
  • @Gabe, the implementation of double-checked locking is fine, it's just that the whole pattern is broken, as per the link. (further research finds that it does work now, but it's probably to be avoided: stackoverflow.com/questions/394898/…) Commented Mar 16, 2011 at 13:46
  • 1
    @mgronber: So it's not broken, it's just missing a volatile. Commented Mar 16, 2011 at 14:58
  • 1
    @Gabe: Well, it is broken if the volatile is missing. We do not know the truth, because the example does not have the definition. However, the volatile fixes only the initialization of new instance. The code is still broken because the m_Instance is read twice. It is first read to check that it is non-null and then it is read again when it is returned. A call to ReSync() may set it to null between those two reads. This bug does not even require IA64. Commented Mar 16, 2011 at 15:13