
----Original Message---- From: boost-bounces@lists.boost.org [mailto:boost-bounces@lists.boost.org] On Behalf Of Jeff Garland Sent: 05 April 2007 14:55 To: boost@lists.boost.org Subject: Re: [boost] [system] Why is this not header-only?
Kevin Yuan wrote:
2007/4/4, Martin Bonner <Martin.Bonner@pi-shurlok.com>: Static variable in an inline function.
Yes, I agree. Something like:
// st.h class st { private: st(){} public: static st* get_instance() { static st* inst = new st; return inst; } };
Yeah sure, classic Meyer's singleton. Couple problems.
It's not thread safe
Granted. (And this could be a major issue).
and you could easily inline this code into multiple translation units. That's harmless. The compiler is supposed to make sure there is only one copy of the singleton variable.
BUT The standard doesnt recognize the existance of DLLs/SOs - and you WILL get multiple copies of the singleton variable in different DLLs.
It's this sort of thing that makes true singletons devilishly hard to do...
No argument there! -- Martin Bonner Project Leader PI SHURLOK LTD Telephone: +44 1223 441434 / 203894 (direct) Fax: +44 1223 203999 Email: martin.bonner@pi-shurlok.com www.pi-shurlok.com