[cpp-threads] static locals
Kevlin Henney
kevlin at curbralan.com
Tue May 31 00:10:34 BST 2005
In message <002b01c5655c$8f0986d0$6401a8c0 at pdimov2>, Peter Dimov
<pdimov at mmltd.net> writes
>Alexander Terekhov wrote:
>> On 5/30/05, Peter Dimov <pdimov at mmltd.net> wrote:
>> [...]
>>> void f()
>>> {
>>> static Q* p = new Q( ... );
>>
>> static(synchronized) or something to distinguish it from
>> threads-unaware lazi-init -- just suppose that "new Q( ... )" is
>> "lock-free" (but not necessarily "thread-safe"). Why the heck do you
>> want to penalize all users of "classic" local statics with IA64-like
>> lazy-init guards and ld.acq on fast path (TSD/TLS variation of DCSI
>> aside for a moment)?
>
>Because...
>
>1. Solutions that do not need syntactic language changes have better
>chances to be accepted;
However, solutions that require changes to the interpretation of an
existing language feature have less chance of being accepted.
>2. It is better to be safe by default than fast but potentially unsafe
>by default;
This is C++ ;-)
However, we already have a concept of safe by default: variables are not
by default static. Programmers wishing to use statics in multithreaded
C++ programs do so at their own risk, but it is not a style to be
encouraged.
>3. I can get the unsafe behavior if I want to by using a static bool;
>
>and
>
>4. It is possible to optimize the thread-safe init quite well, in
>principle, and compiler writers are much more likely to invest in such
>optimizations if the default is thread-safe.
I suspect it is worth polling more compiler writers about this. Given
some of what I have heard from a couple of them, I am not sure that they
would necessarily go along with this view of investment.
If we were starting over, with a new language etc, I would back your
point of view completely, but C++ is not a clean slate -- compromise is
more than likely; it is necessary :-}
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