Deutsch   English   Français   Italiano  
<39d63ce8e33629caf9f9355ba55b7e0c1c23ef0f@i2pn2.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!eternal-september.org!feeder3.eternal-september.org!i2pn.org!i2pn2.org!.POSTED!not-for-mail
From: Richard Damon <richard@damon-family.org>
Newsgroups: comp.lang.c++
Subject: Re: Pre-main construction order in modules
Date: Sun, 30 Mar 2025 15:01:24 -0400
Organization: i2pn2 (i2pn.org)
Message-ID: <39d63ce8e33629caf9f9355ba55b7e0c1c23ef0f@i2pn2.org>
References: <vsb12i$2mv42$1@dont-email.me> <vsbl21$1jsvi$1@dont-email.me>
 <vsbo2p$1p5ov$1@dont-email.me> <dTdGP.136957$cgs7.71710@fx14.ams4>
 <vsbqc2$1rk0n$1@dont-email.me> <48eGP.730204$J61.500281@fx08.ams4>
 <vsc0o9$2294v$2@raubtier-asyl.eternal-september.org>
 <5HfGP.241316$i41.190620@fx06.ams4>
 <vsc15c$22qfr$1@raubtier-asyl.eternal-september.org>
 <pLfGP.630914$Kb9a.52361@fx16.ams4>
 <vsc1b1$230rd$1@raubtier-asyl.eternal-september.org>
 <JPfGP.1508894$gHk7.1105564@fx17.ams4>
 <vsc1r1$23fpb$1@raubtier-asyl.eternal-september.org>
 <DXfGP.206189$Xb1.36076@fx05.ams4>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 30 Mar 2025 19:03:21 -0000 (UTC)
Injection-Info: i2pn2.org;
	logging-data="2434641"; mail-complaints-to="usenet@i2pn2.org";
	posting-account="diqKR1lalukngNWEqoq9/uFtbkm5U+w3w6FQ0yesrXg";
User-Agent: Mozilla Thunderbird
Content-Language: en-US
In-Reply-To: <DXfGP.206189$Xb1.36076@fx05.ams4>
X-Spam-Checker-Version: SpamAssassin 4.0.0
Bytes: 2721
Lines: 27

On 3/30/25 2:20 PM, Mr Flibble wrote:
> On Sun, 30 Mar 2025 20:17:23 +0200, Bonita Montero wrote:
> 
>> Am 30.03.2025 um 20:11 schrieb Mr Flibble:
>>
>>> No what I meant was the Meyers Singleton which involves static local
>>> variables NOT static member variables which is what YOU thought it
>>> meant.
>>
>> static local variables need double-checked locked initialization.
>> That's rather slow to just get a reference.
> 
> But that is nevertheless what the Meyers Singleton involves.  Static local
> initialisation has been threadsafe since C++11 and if performance is a
> concern then you can always cache the result in a reference downstream in
> any hot path that needs it.
> 
> /Flibble

Yes, my typical implementation is a global pointer (or static member of 
a class, not significantly different in function), which code can do a 
check for zero, if it sees it zero calls the generator function which 
sets the variable to the address of the local static variable.

The check for zero needs no guard, as redundant calls to the function 
are harmless, costing only the extra interlocking operation, and will be 
limited to code that reaches that pointer within the time frame needed 
to initialize the object.