game-programming-patterns icon indicating copy to clipboard operation
game-programming-patterns copied to clipboard

Singleton "Limit a class to a single instance" example isn't thread safe

Open munificent opened this issue 9 years ago • 0 comments

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.

munificent avatar Oct 31 '16 15:10 munificent