game-programming-patterns
game-programming-patterns copied to clipboard
Singleton "Limit a class to a single instance" example isn't thread safe
From Adolfo Ochagavía, this example isn't thead-safe:
class FileSystem
{
public:
FileSystem()
{
assert(!instantiated_);
instantiated_ = true;
}
~FileSystem() { instantiated_ = false; }
private:
static bool instantiated_;
};
bool FileSystem::instantiated_ = false;
The earlier singleton pattern is. Probably just need to do something similar for this one.