|
Boost : |
From: Steven Watanabe (steven_at_[hidden])
Date: 2007-02-05 16:31:36
AMDG
Andreas Huber <ahd6974-spamgroupstrap <at> yahoo.com> writes:
> I should have been clearer. The standard sais that *initializing* a POD
> is not a problem because that is done before any threads have a chance
> to race against each other (typically when the binary is loaded into
> memory).
> <snip>
>
> static int & GetPodInstance()
> {
> static int podInstance = 42;
> return podInstance;
> }
> <snip>
> When multiple threads are present, there's no race condition when more
> than one of them call GetPodInstance(). Clearly there is one when they
> call GetNonPodInstance() because NonPod::NonPod() will non run before
> the first call...
>
GetPodInstance() is probably safe, but the standard does
not require it. "A local object of POD type (3.9) with static
storage duration initialized with constant-expressions is
initialized before its block is first entered." (6.7/4)
In Christ,
Steven Watanabe
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk