From: Jeff Garland (jeff_at_[hidden])
Date: 2007-04-05 10:47:42
Kevin Yuan wrote:
> 2007/4/5, Jeff Garland <jeff_at_[hidden]>:
>> Yeah sure, classic Meyer's singleton. Couple problems. It's not thread safe
> It may be not thread safe. If it is first called in the "single thread
> initialization phase"(or a term like that) there wil be no thread
> safty problem, but no "lazy instantiation" as well.
Well, now you've added a requirement that to use this correctly I need a
'single threaded' init? I assure you, that's sometimes just not possible.
I've seen plenty of software where the first thing that happens is multiple
threads are spawned (before 'main' even gets invoked) so it's not always that
easy. And when you throw dll loading into the mix it's basically impossible
to guarantee a startup order.
>> and you could easily inline this code into multiple translation units.
> I don't agree. Compiler should not make multiple instances of a
> <b>static local</b> variable,
See other mail/discussion regarding complexities caused by dlls on Windows.
Yes, "in theory" this is prevented by the compiler, but the compiler isn't all
to a typical real-world build process.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk