[cpp-threads] static locals
Peter Dimov
pdimov at mmltd.net
Thu Jun 2 13:14:57 BST 2005
Boehm, Hans wrote:
> With traditional approaches to optimization, I agree. But
> that's not a restriction we can put in the standard.
>
> As it stands, a compiler is allowed to look at the whole
> program, deduce that only two threads execute this code,
> observe that this code will only be run on some hypothetical
> new machine where both threads run in lock-step, and hence
> thread 1 will always perform the initialization first.
> Thus it knows what the initialization value will be, even
> though it's not the same for all valid executions. My reading
> is that static initialization is allowed in such cases.
>
> The real issue is that the programmer has no way to
> reason about visibility, since there is no rule that clearly
> prohibits static initialization.
I think that this specific issue is the least of our worries. No compiler
ever will break synchronized dynamic initialization in this way, regardless
of what 3.6.2/2 says, just like today's compilers don't optimize out dynamic
initializers that write to std::cout and return a constant value
(technically, they are allowed to). A clarification won't hurt, of course.
More information about the cpp-threads
mailing list