|
From: Kakhkhor A. <kab...@gm...> - 2010-09-01 10:24:10
|
I think it is broken just like the design using scoped_ptr or the
original design. Consider what happens when Singleton's instance is
used in two implementation files.
// file1.cpp
namespace {
SingletonObject* const ptr = &SingletonObject::instance();
}
// file2.cpp
namespace {
SingletonObject* const ptr = &SingletonObject::instance();
}
Who get's to build the singleton?
The only way to avoid this problem is to make the instance itself a
static local and forget about session ID. Each session would have to
reset the singleton, if needed.
A half-solution is to make sure that no instance is crated before
main() is launched. That means no static objects using singleton.
Which way we go?
|