[cpp-threads] static locals (was: Memory model counterproposal...)

Kevlin Henney kevlin at curbralan.com
Sun May 29 07:24:58 BST 2005


In message <03d701c562fb$77e86740$6401a8c0 at pdimov2>, Peter Dimov 
<pdimov at mmltd.net> writes
>Andrei Alexandrescu wrote:
>> Alexander Terekhov wrote:
>>> static(synchronized) X * p = new X;
>>
>> So 'synchronized' would be a contextual keyword. C++ doesn't have any
>> (although I personally like them), and as such we might encounter
>> resistance.
>>
>> Maybe the uglier
>>
>> static "once" vardecl
>>
>> might have more success.
>
>What's wrong with Hans's original suggestion of protected static? It 
>doesn't require a new keyword or contextual syntax.

I think it is perhaps worth taking a step back and nipping a trend in 
the bud before it messes things up too much.

In order to specify a decent memory model in C++ for MT programs, there 
are a number of declarative gaps that need to be filled in specifying 
various operational attributes for variables. There are two related but 
sufficiently separate questions: (1) What operational attributes need to 
be declared? (2) What is their concrete syntax in C++? Where (1) is 
primarily a technical matter, (2) brings with it more political 
considerations. Importantly, consideration of (2) should not derail 
consideration of and progress on (1). The dog should be wagging the 
tail, not vice-versa.

The problem so far is that the approach for (2) is looking a little 
incoherent in style, and the list of things to be added appears to be 
growing, so having a more uniform model for extension seems to be 
desirable.

So far there has been the discussion of whether to extend the meaning of 
an existing keyword -- ie volatile, so that it covers both 
signal/longjmp volatility and thread volatility -- the addition of 
(ugly) double-underscore prefixed words -- eg __async -- the reuse of 
existing keywords in new syntax arrangements -- eg protected static -- 
and contextual keywords.

I suspect that separating (1) from (2) more explicitly would help move 
the memory model proposal forward, and adopting a more regular model for 
qualifying declarations would help both this effort and other similar 
needs in C++.

C++ currently lacks what MIDL and C# refer to as attributes and Java 
refers to as annotations, but I guess something like that is essentially 
what seems to make sense here. Does anyone know if there are any 
proposals on the table for C++ in this area? I can't recall anything off 
the top of my head. Either the MS way of using [...] to enclose 
attribute information or the style that Andrei mentioned above, based on 
string literals. This latter form has the advantage that there is 
already prior art for it in C++, namely the linkage specifier, eg extern 
"C". So protected static would become something like static 
"synchronized", __async would become something like volatile "thread", 
with the default meaning of volatile being something like volatile 
"signal", and so on.

Although a step in a different direction, I think this syntax and 
separation of concerns would be clearer and, regardless of the precise 
syntax eventually adopted, in the near future this approach is less 
likely to get sidetracked by syntax-related discussions, debates and 
dead ends when there are deeper technical issues at stake.

Thoughts?

Kevlin
-- 
____________________________________________________________

   Kevlin Henney                   phone:  +44 117 942 2990
   mailto:kevlin at curbralan.com     mobile: +44 7801 073 508
   http://www.curbralan.com        fax:    +44 870 052 2289
   Curbralan: Consultancy + Training + Development + Review
____________________________________________________________




More information about the cpp-threads mailing list