|
Boost : |
From: Martin Bonner (Martin.Bonner_at_[hidden])
Date: 2007-04-05 10:00:29
----Original Message----
From: boost-bounces_at_[hidden]
[mailto:boost-bounces_at_[hidden]] On Behalf Of Jeff Garland Sent:
05 April 2007 14:55 To: boost_at_[hidden]
Subject: Re: [boost] [system] Why is this not header-only?
> Kevin Yuan wrote:
>>> 2007/4/4, Martin Bonner <Martin.Bonner_at_[hidden]>:
>>> 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_at_[hidden] www.pi-shurlok.com
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk