When to use and not to use singletons

Started by
51 comments, last by AnthonyG 16 years, 11 months ago
Quote:Original post by jpetrieDon't forget threading and double checked locking issues related to singletons. The amount of writing about that stuff is unbelievable.


Saying that double checked locking doesn't work in C++ is a sleight of hand.
The paper that originally made the claim is misleading - it spends a huge amount of time talking about the exact guarentees that the C++ standard gives in relation to order of execution - but the C++ standard is irrelevant to the issue, because threads cannot be created in standard C++.

To create a thread in C++ an external libary must be used. All such libraries provide some sort of memory barrier construct, which can be used to safely implement double checked locking.

Other languages that provide sensible threading models allow double checked locking to be implemented perfectly safely (notably C# but not Java).
Advertisement
You misquoted that; I didn't say it. ;)
That was Promit:

http://www.gamedev.net/community/forums/viewreply.asp?ID=2971605
-AnthonyG

This topic is closed to new replies.

Advertisement