[cpp-threads] static locals

Boehm, Hans hans.boehm at hp.com
Tue May 31 19:17:43 BST 2005


> Yes, you are right. I thought about "all side effects and all 
> dependencies 
> should be visible" but this is too complicated and probably 
> doesn't buy 
> anything. So all prior writes it is (but only in the dynamic 
> initialization 
> case, of course). 
> 
I have two concerns with requiring this in all cases:

1) The overhead in cases in which it isn't needed.  (On most X86
processors, it probably doesn't matter.  My impression is
that on PowerPC (and Alpha), it's an issue.  Most others are
somewhere in the middle.)

2) (More important to me personally.)  Distinguishing the static
and dynamic case here seems very ugly to me.  AFAICT, the standard
currently allows "dynamic" initializations to be performed statically,
at the compiler's discretion.  Currently, that's OK, because static
initialization has stronger properties.  But now, it would cause a
memory barrier to be eliminated.  One could make that more tolerable
by eliminating the memory barrier only in the constant expression case.
But that's still extremely confusing, since the constant expression
rules are fairly complicated.  I really don't want the memory ordering
semantics to become weaker because I accidentally deleted a conversion
that was no longer needed.

If we have two variants, then I think the synchronized case should
always ensure ordering, whether the initialization is done
statically or not.  In this case it would be nice to have some way
to assert that something is a constant expression, in cases in
which we don't need the ordering.  Is there currently a way to do
that? 

Hans




More information about the cpp-threads mailing list