Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"A verbal contract isn't worth the paper it's printed on." -- Samuel Goldwyn


devel / comp.lang.c++ / Re: Thread-safe initialization of static objects

SubjectAuthor
* Thread-safe initialization of static objectsBonita Montero
+* Re: Thread-safe initialization of static objectsPavel
|+* Re: Thread-safe initialization of static objectsBonita Montero
||+* Re: Thread-safe initialization of static objectsPavel
|||`* Re: Thread-safe initialization of static objectsBonita Montero
||| `* Re: Thread-safe initialization of static objectsPavel
|||  `* Re: Thread-safe initialization of static objectsBonita Montero
|||   +* Re: Thread-safe initialization of static objectsScott Lurndal
|||   |+* Re: Thread-safe initialization of static objectsRichard Damon
|||   ||`* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   || `* Re: Thread-safe initialization of static objectsRichard Damon
|||   ||  `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   ||   +* Re: Thread-safe initialization of static objectsRichard Damon
|||   ||   |`- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   ||   `* Re: Thread-safe initialization of static objectsScott Lurndal
|||   ||    `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   |`- Re: Thread-safe initialization of static objectsBonita Montero
|||   +* Re: Thread-safe initialization of static objectsPavel
|||   |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | +* Re: Thread-safe initialization of static objectsPavel
|||   | |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | +* Re: Thread-safe initialization of static objectsPaavo Helde
|||   | | |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | +* Re: Thread-safe initialization of static objectsPavel
|||   | | | |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | +* Re: Thread-safe initialization of static objectsRichard Damon
|||   | | | | |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | +* Re: Thread-safe initialization of static objectsRichard Damon
|||   | | | | | |+* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | ||+* Re: Thread-safe initialization of static objectsPaavo Helde
|||   | | | | | |||+* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | ||||+- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | | | | ||||`* Re: Thread-safe initialization of static objectsPaavo Helde
|||   | | | | | |||| +* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | |||| |+- Re: Thread-safe initialization of static objectsRichard Damon
|||   | | | | | |||| |`- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | | | | |||| `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | ||||  `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | ||||   `* Re: Thread-safe initialization of static objectsPaavo Helde
|||   | | | | | ||||    +- Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | ||||    `- Re: Thread-safe initialization of static objectsBonita Montero
|||   | | | | | |||`* Re: Thread-safe initialization of static objectsMichael S
|||   | | | | | ||| +- Re: Thread-safe initialization of static objectsScott Lurndal
|||   | | | | | ||| `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | | | | ||`* Re: Thread-safe initialization of static objectsRichard Damon
|||   | | | | | || `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | | | | |`* Re: Thread-safe initialization of static objectsPavel
|||   | | | | | | `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | | | | |  `* Re: Thread-safe initialization of static objectsPavel
|||   | | | | | |   `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | | | | |    `- Re: Thread-safe initialization of static objectsPavel
|||   | | | | | `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | | | `- Re: Thread-safe initialization of static objectsPavel
|||   | | | `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |  `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |   +* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |   |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |   | `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |   |  +- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |   |  `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |   |   +- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |   |   `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |   +- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |   `* Re: Thread-safe initialization of static objectsRichard Damon
|||   | | |    `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |     +- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |     `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |      `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |       `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |        `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |         `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |          `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |           `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |            `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |             `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |              +- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |              `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |               `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                 `* Re: Thread-safe initialization of static objectsScott Lurndal
|||   | | |                  +- Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                  `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                   `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                    `* Re: Thread-safe initialization of static objectsRichard Damon
|||   | | |                     `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                      `* Re: Thread-safe initialization of static objectsPavel
|||   | | |                       `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        +* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        | `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |  `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        |   +* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |   |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        |   | +* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |   | |`* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        |   | | `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |   | |  `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        |   | |   `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |   | |    `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        |   | |     `* Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |   | |      `* Re: Thread-safe initialization of static objectsBonita Montero
|||   | | |                        |   | `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | | |                        |   `* Re: Thread-safe initialization of static objectsKaz Kylheku
|||   | | |                        `* Re: Thread-safe initialization of static objectsPavel
|||   | | `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   | `- Re: Thread-safe initialization of static objectsChris M. Thomasson
|||   `- Re: Thread-safe initialization of static objectsMarcel Mueller
||`- Re: Thread-safe initialization of static objectsChris M. Thomasson
|`* Re: Thread-safe initialization of static objectsChris M. Thomasson
+* Re: Thread-safe initialization of static objectsPaavo Helde
+* Re: Thread-safe initialization of static objectsChris M. Thomasson
+* Re: Thread-safe initialization of static objectsChris M. Thomasson
`* Re: Thread-safe initialization of static objectsFrederick Virchanza Gotham

Pages:123456789101112131415161718192021222324252627
Re: Thread-safe initialization of static objects

<udl2fv$m1ie$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1419&group=comp.lang.c%2B%2B#1419

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sun, 10 Sep 2023 21:38:54 +0300
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <udl2fv$m1ie$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 18:38:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="7abe9392a749e386a1f2f35554478286";
logging-data="722510"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7l9b4dv1yWxrCeHOj0EKpfLbBwXed4qY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:YFo7ArKajI8JPxU7km8Tm+wIHx0=
Content-Language: en-US
In-Reply-To: <udkq3u$koun$1@dont-email.me>
 by: Paavo Helde - Sun, 10 Sep 2023 18:38 UTC

10.09.2023 19:15 Bonita Montero kirjutas:
> Am 10.09.2023 um 18:08 schrieb Paavo Helde:
>
>> Which variant do you prefer? And how would this help the programmer
>> who needs to write programs in C++? Should they just avoid creating
>> any static variables at all, in order to not trigger this failure
>> scenario?
>
> It should be handled like synchronization on a std::mutex,
> which can fail with a system_error. If this would happen
> the object would remain uninitialized.

Meaning that a program can never access any static variable, because
accessing of an uninitialized object would be UB. Great job!

Re: Thread-safe initialization of static objects

<A_qLM.257894$JG_b.81867@fx39.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1420&group=comp.lang.c%2B%2B#1420

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx39.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbqs7$2t34f$1@dont-email.me> <udbs1f$2t79o$1@dont-email.me>
<udbtda$2tdm8$1@dont-email.me> <udcf19$2vuf5$1@dont-email.me>
<udd6vm$33f8r$1@dont-email.me> <udd87f$33lr1$1@dont-email.me>
<udd90h$33peq$1@dont-email.me> <udda40$33ub2$1@dont-email.me>
<udg01c$3m3qc$2@dont-email.me> <4OOKM.167484$uEkc.38090@fx35.iad>
<udggc7$3ou77$1@dont-email.me> <udggmi$3ou77$2@dont-email.me>
<7p2LM.1449513$GMN3.1325499@fx16.iad> <udj9o1$dg67$1@dont-email.me>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <udj9o1$dg67$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 74
Message-ID: <A_qLM.257894$JG_b.81867@fx39.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sun, 10 Sep 2023 21:58:56 UTC
Date: Sun, 10 Sep 2023 17:58:56 -0400
X-Received-Bytes: 4065
 by: Pavel - Sun, 10 Sep 2023 21:58 UTC

Chris M. Thomasson wrote:
> On 9/9/2023 11:00 AM, Pavel wrote:
>> Chris M. Thomasson wrote:
>>> On 9/8/2023 6:05 PM, Chris M. Thomasson wrote:
>>>> On 9/8/2023 5:14 PM, Pavel wrote:
>>>>> Chris M. Thomasson wrote:
>>>>>> On 9/7/2023 1:00 PM, Bonita Montero wrote:
>>>>>>> Am 07.09.2023 um 21:41 schrieb Chris M. Thomasson:
>>>>>>>
>>>>>>>> Yup. It uses address based hashing into the fixed mutex table.
>>>>>>>
>>>>>>> I guess that's not used at all in the runtimes.
>>>>>>>
>>>>>>
>>>>>> Why not?
>>>>>
>>>>> I think it's not needed in general for static initialization purpose.
>>>>>
>>>>> This is because, if our design choice for our "C++ compiler" is to
>>>>> use a dedicated mutex (or once_flag control) per a static variable
>>>>> that requires dynamic initialization, nothing prevents our compiler
>>>>> from allocating a static instance of such mutex or control next to
>>>>> the static variable.
>>>>>
>>>>> Because mutex and once_flag can be constant-initialized (at least
>>>>> in POSIX, notably Linux), the code that dynamically initializes a
>>>>> variable can directly use the address of its respective
>>>>> constant-initialized mutex or control, as in the following example:
>>>>>
>>>>> code in C++ source file:
>>>>>
>>>>> static type1 var1 = InitVar1();
>>>>>
>>>>> **pseudo-code** actually generated by the compiler:
>>>>>
>>>>> pthread_once_t __var1_once_control = PTHREAD_ONCE_INIT; /* generated
>>>>> by the compiler when  */
>>>>>
>>>>> static type1 var1 = InitVar1(); /* this is compiled to,
>>>>> **in pseudo-code**, to something like
>>>>>
>>>>>   pthread_once( [&var1]() { var1 = InitVar1(); } );
>>>>> */
>>>>
>>>> pthread_once is perfectly fine. Just wondering, are you creating the
>>>> POSIX impl directly here?
>>>
>>> Think of how you would directly implement pthread_once... There are
>>> many different ways.
>> You are correct, there are. Fortunately, I don't have to reinvent this
>> particular wheel as the implementation source code is available for
>> everyone to read. On Linux, Futex is a natural choice.
>>
>> Other platforms can have theirs. I did not program for Windows for
>> long time but I would at least try to implement call_once with a
>> critical section (whose creation, contrary to OP's insinuations,
>> cannot fail since Windows Vista).
>
> Windows has:
>
> https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initonceexecuteonce
>
>
> https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-initonceinitialize
Thanks, this does seem to be a simple user-friendly API that is most
appropriate to implement static initialization as in C++.

>
>
> This is their part of their "futex" API:
>
> https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress
>

Re: Thread-safe initialization of static objects

<V4rLM.868795$U3w1.60865@fx09.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1421&group=comp.lang.c%2B%2B#1421

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <udig8l$6ddc$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 13
Message-ID: <V4rLM.868795$U3w1.60865@fx09.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sun, 10 Sep 2023 22:05:41 UTC
Date: Sun, 10 Sep 2023 18:05:35 -0400
X-Received-Bytes: 1662
 by: Pavel - Sun, 10 Sep 2023 22:05 UTC

Bonita Montero wrote:
> Am 09.09.2023 um 19:42 schrieb Pavel:
>
>> If Microsoft implemented standard wrongly, it's Microsoft's failure,
>> not the standard's.
>
> The standard doesn't say anything to the issue I've shown.
>
You did not show any issue, you just guessed what the implementation
could be and assumed there could be an issue.

After looking at InitOnceExecuteOnce API pointed out by Chris I think it
is very likely that your guess on implementation was wrong.

Re: Thread-safe initialization of static objects

<fLrLM.1141591$mPI2.986632@fx15.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1422&group=comp.lang.c%2B%2B#1422

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx15.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <hRjLM.1455228$GMN3.816986@fx16.iad>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 53
Message-ID: <fLrLM.1141591$mPI2.986632@fx15.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sun, 10 Sep 2023 22:50:51 UTC
Date: Sun, 10 Sep 2023 18:50:51 -0400
X-Received-Bytes: 3651
 by: Pavel - Sun, 10 Sep 2023 22:50 UTC

Richard Damon wrote:
> On 9/10/23 1:57 AM, Bonita Montero wrote:
>> Am 09.09.2023 um 22:37 schrieb Richard Damon:
>>
>>> The Standard defines the final results that must happen
>>> (or possibilities that can happen in some cases).
>>
>> The standards also should consider side effects as in this example
>> when a static initialization would fail because of a synchronization
>> error.
>>
> You don't seem to understand that sincd it CAN be done in a way that
> always works, any method that doesn't always work is just WRONG and
> non-conforming.
>
> I guess you think that 1 + 1 must be allowed to be 1 in case of
> "synchronization errors".
>
> Static Initialization has DEFINED behavior, and that behavior must be
> honored, and the implementation do what is need to make that happen.
>
> Methods have been shown to do it (perhaps less performant than this is
> some conditions),
Actually, I think there should be always a better-performing method to
implement C++ static initialization than using windows or pthread mutex
-- e.g. using a specialized control like those used for call_once
implementation -- at least on UNIX or Windows.

This is because IMHO mutex API is a textbook case of feature bloat on
both platforms.

E.g. in standard UNIX (former POSIX), you can have recursive / robust /
shared / errorcheck mutex (not all mutually exclusive) and who knows
what else. pthread_mutex_lock shall be able to deal with either
combination and the feature-check code makes (at least the current)
implementation quite messy, with multiple dispatches on the same condition.

On Windows, the number of options is less; but, to compensate for that
:-), a mutex is always recursive plus wait functions have to know how to
deal with inter-process mutexes because any handle passed to them can
turn out to be of an inter-process mutex (or even not a mutex at all).
Therefore, I do not think their use for static initialization (that does
not require either recursive or inter-process lock) even could be optimal.

> so it is possible, so you can't say the Standard is
> asking for impossible behavior, thus any "optimizations" that don't meet
> that defined behavior are just WRONG.
>
> Saying something wrong must be made right is just WRONG, so you are
> WRONG in your claim.
>
> PERIOD.

Re: Thread-safe initialization of static objects

<udlsg6$t76q$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1423&group=comp.lang.c%2B%2B#1423

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 04:02:46 +0200
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <udlsg6$t76q$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me> <udl2fv$m1ie$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 02:02:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9bf3d5b50b6abadc4d9afd539a9b4fc8";
logging-data="957658"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+xfBPpUkh7qrz86wjMV2GGeSHPL1w/4aU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ReVXvnis9K2wrn3IJ5nayffu2ZQ=
Content-Language: de-DE
In-Reply-To: <udl2fv$m1ie$1@dont-email.me>
 by: Bonita Montero - Mon, 11 Sep 2023 02:02 UTC

Am 10.09.2023 um 20:38 schrieb Paavo Helde:

> Meaning that a program can never access any static variable, because
> accessing of an uninitialized object would be UB. Great job!

Exactly the same thing can happen when locking a mutex,
which can also throw system_error. Do you think it is
unnecessary that a mutex can throw this exception ?

Re: Thread-safe initialization of static objects

<GUvLM.344873$ens9.113242@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1424&group=comp.lang.c%2B%2B#1424

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Thread-safe initialization of static objects
Content-Language: en-US
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me> <udl2fv$m1ie$1@dont-email.me>
<udlsg6$t76q$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <udlsg6$t76q$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 16
Message-ID: <GUvLM.344873$ens9.113242@fx45.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 10 Sep 2023 20:33:56 -0700
X-Received-Bytes: 2002
 by: Richard Damon - Mon, 11 Sep 2023 03:33 UTC

On 9/10/23 7:02 PM, Bonita Montero wrote:
> Am 10.09.2023 um 20:38 schrieb Paavo Helde:
>
>> Meaning that a program can never access any static variable, because
>> accessing of an uninitialized object would be UB. Great job!
>
> Exactly the same thing can happen when locking a mutex,
> which can also throw system_error. Do you think it is
> unnecessary that a mutex can throw this exception ?
>
>

Why does the Mutex throw "system_error" if it has already been
constructed and not misused?

Re: Thread-safe initialization of static objects

<udm5rf$u6g6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1426&group=comp.lang.c%2B%2B#1426

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sun, 10 Sep 2023 21:42:20 -0700
Organization: A noiseless patient Spider
Lines: 111
Message-ID: <udm5rf$u6g6$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<fLrLM.1141591$mPI2.986632@fx15.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 04:42:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="23a839a520af8f67c5f88d72ed24e588";
logging-data="989702"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/5ui+f+n7FFiJpFGFYupAteE5sZxMx8/o="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:TebFoawqRyXErz5opO9C3AhuKt0=
Content-Language: en-US
In-Reply-To: <fLrLM.1141591$mPI2.986632@fx15.iad>
 by: Chris M. Thomasson - Mon, 11 Sep 2023 04:42 UTC

On 9/10/2023 3:50 PM, Pavel wrote:
> Richard Damon wrote:
>> On 9/10/23 1:57 AM, Bonita Montero wrote:
>>> Am 09.09.2023 um 22:37 schrieb Richard Damon:
>>>
>>>> The Standard defines the final results that must happen
>>>> (or possibilities that can happen in some cases).
>>>
>>> The standards also should consider side effects as in this example
>>> when a static initialization would fail because of a synchronization
>>> error.
>>>
>> You don't seem to understand that sincd it CAN be done in a way that
>> always works, any method that doesn't always work is just WRONG and
>> non-conforming.
>>
>> I guess you think that 1 + 1 must be allowed to be 1 in case of
>> "synchronization errors".
>>
>> Static Initialization has DEFINED behavior, and that behavior must be
>> honored, and the implementation do what is need to make that happen.
>>
>> Methods have been shown to do it (perhaps less performant than this is
>> some conditions),
> Actually, I think there should be always a better-performing method to
> implement C++ static initialization than using windows or pthread mutex
> -- e.g. using a specialized control like those used for call_once
> implementation -- at least on UNIX or Windows.
>
> This is because IMHO mutex API is a textbook case of feature bloat on
> both platforms.
>
> E.g. in standard UNIX (former POSIX), you can have recursive / robust /
> shared / errorcheck mutex (not all mutually exclusive) and who knows
> what else. pthread_mutex_lock shall be able to deal with either
> combination and the feature-check code makes (at least the current)
> implementation quite messy, with multiple dispatches on the same condition.
>
> On Windows, the number of options is less; but, to compensate for that
> :-), a mutex is always recursive plus wait functions have to know how to
> deal with inter-process mutexes because any handle passed to them can
> turn out to be of an inter-process mutex (or even not a mutex at all).
> Therefore, I do not think their use for static initialization (that does
> not require either recursive or inter-process lock) even could be optimal.

I might be missing your point here. Humm... Even though POSIX has all of
these different types of mutexs, we can use them by organization. So,
wrt windows, an intra-process mutex can be a CRITICAL_SECTION. Or an
inter-process as a mutex HANDLE.

https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createmutexexa

Wrt the inter-process route we may need to deal with WAIT_ABANDONED, or
EOWNERDEAD wrt POSIX. So we create different types:

struct intra_process_mutex
{ CRITICAL_SECTION m_os_lock;
};

struct inter_process_mutex
{ HANDLE m_os_lock;
};

struct inter_process_mutex_robust
{ HANDLE m_os_lock;
};

These simple types can be rather easy to reason about. Wrt POSIX, the
different types would be:

struct intra_process_mutex
{ pthread_mutex_t m_os_lock;
};

struct inter_process_mutex
{ pthread_mutex_t m_os_lock;
};

struct inter_process_mutex_robust
{ pthread_mutex_t m_os_lock;
};

The point is trying to organize things a bit here.

Sound somewhat decent?

>
>> so it is possible, so you can't say the Standard is asking for
>> impossible behavior, thus any "optimizations" that don't meet that
>> defined behavior are just WRONG.
>>
>> Saying something wrong must be made right is just WRONG, so you are
>> WRONG in your claim.
>>
>> PERIOD.
>

Re: Thread-safe initialization of static objects

<udm6b7$u6gu$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1427&group=comp.lang.c%2B%2B#1427

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sun, 10 Sep 2023 21:50:46 -0700
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <udm6b7$u6gu$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me> <udl2fv$m1ie$1@dont-email.me>
<udlsg6$t76q$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 04:50:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="23a839a520af8f67c5f88d72ed24e588";
logging-data="989726"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1950OoFXInGLp6xn02b/kKiYx/IgCzrn8g="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Dv5euupVfzGYyOz6tUKV+kJtw9k=
Content-Language: en-US
In-Reply-To: <udlsg6$t76q$1@dont-email.me>
 by: Chris M. Thomasson - Mon, 11 Sep 2023 04:50 UTC

On 9/10/2023 7:02 PM, Bonita Montero wrote:
> Am 10.09.2023 um 20:38 schrieb Paavo Helde:
>
>> Meaning that a program can never access any static variable, because
>> accessing of an uninitialized object would be UB. Great job!
>
> Exactly the same thing can happen when locking a mutex,
> which can also throw system_error. Do you think it is
> unnecessary that a mutex can throw this exception ?
>
>

Read about what can happen to the windows "futex" during periods of hard
stress on the OS, low memory, most likely very low non-paged memory,
"almost" getting to a blue screen type of shit! damn, anyway:
___________________________
Note WaitOnAddress is guaranteed to return when the address is
signaled, but it is also allowed to return for other reasons. For this
reason, after WaitOnAddress returns the caller should compare the new
value with the original undesired value to confirm that the value has
actually changed. For example, the following circumstances can result in
waking the thread early:
Low memory conditions
A previous wake on the same address was abandoned
Executing code on a checked build of the operating system
___________________________

Take special note "Low memory conditions"...

I bet their call once logic is using their "futex" logic. Humm... Anyone
have any insight into the windows possible internal impl? I want to read
sysinternals magazine again... I used to have it delivered to my house. ;^)

https://learn.microsoft.com/en-us/sysinternals/

;^)

Re: Thread-safe initialization of static objects

<udn5jc$12oal$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1433&group=comp.lang.c%2B%2B#1433

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 15:44:12 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <udn5jc$12oal$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me> <udl2fv$m1ie$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 13:44:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9bf3d5b50b6abadc4d9afd539a9b4fc8";
logging-data="1139029"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18MzCgrx0S6xl/jEV9Z7VQk94faIhUDtZ4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:YrTRdZJ6ld3TJURPR7/mTbFGBUI=
In-Reply-To: <udl2fv$m1ie$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Mon, 11 Sep 2023 13:44 UTC

Am 10.09.2023 um 20:38 schrieb Paavo Helde:

> Meaning that a program can never access any static variable, because
> accessing of an uninitialized object would be UB. Great job!

That's the same as when the static object's constructor throws,
i.e. the object will get another try if you get again to the
initialization. And if an exception is thrown the context of
the definition is left to the next exception handler that you
won't operate on a non initialized object.
I don't see where's the problem here.

Re: Thread-safe initialization of static objects

<udn5sm$12qs5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1434&group=comp.lang.c%2B%2B#1434

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 15:49:10 +0200
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <udn5sm$12qs5$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me> <udl2fv$m1ie$1@dont-email.me>
<udn5jc$12oal$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 13:49:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9bf3d5b50b6abadc4d9afd539a9b4fc8";
logging-data="1141637"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/psqn/tPP3X0h2+G32P7JQUC99BFDrYOc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:J4BbreMhAunFjlrVsBBKj2E9Xsk=
Content-Language: de-DE
In-Reply-To: <udn5jc$12oal$1@dont-email.me>
 by: Bonita Montero - Mon, 11 Sep 2023 13:49 UTC

Am 11.09.2023 um 15:44 schrieb Bonita Montero:

> That's the same as when the static object's constructor throws,
> i.e. the object will get another try if you get again to the
> initialization. And if an exception is thrown the context of
> the definition is left to the next exception handler that you
> won't operate on a non initialized object.
> I don't see where's the problem here.

Look at this code:

#include <iostream>

using namespace std;

int main()
{ struct WillReInit
{
WillReInit()
{
throw "hello world";
}
};
for( ; ; )
try
{
static WillReInit wi;
}
catch( char const *str )
{
cout << str << endl;
}
}

Things would be similar if the synchronization would throw, i.e. wri
would be initialized over and over. So there won't be any accessible
uninitialized object.

Re: Thread-safe initialization of static objects

<udn883$135tl$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1435&group=comp.lang.c%2B%2B#1435

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 16:29:22 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <udn883$135tl$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 14:29:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9bf3d5b50b6abadc4d9afd539a9b4fc8";
logging-data="1152949"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/vPGc8d7tyrPf5+4BVvPdqq5B6qnxgLuc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:6gKP0Bv6appwUZBbsMo9nc/4g2A=
In-Reply-To: <udl0ti$lp5v$4@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Mon, 11 Sep 2023 14:29 UTC

Am 10.09.2023 um 20:12 schrieb Chris M. Thomasson:

> So, are you suggesting that the C++ standard should be tightly
> integrated with a given kernel impl? Humm... Strange. POSIX
> aside for a moment...

Not more than it is integrated to the operating system through
throwing system_error, therby having an operating dependent
error code which is translated by the operating system (inter-
nally through strerror() or FormatMessage()).
So it would be most appropriate to throw system_error with an
operating system dependent error code and system_category as
the translator - just like std::mutex does.

Re: Thread-safe initialization of static objects

<udnb84$13n78$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1436&group=comp.lang.c%2B%2B#1436

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesn...@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 18:20:35 +0300
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <udnb84$13n78$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me> <udl2fv$m1ie$1@dont-email.me>
<udn5jc$12oal$1@dont-email.me> <udn5sm$12qs5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Mon, 11 Sep 2023 15:20:36 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="72b750ed3b1f1530703fcb3c50e92319";
logging-data="1170664"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/hGrpaOY+tBpwTgYi5Bezpwe2bFL91qLQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:+flArKSbCNYtk50JXNy+8O+aUEQ=
Content-Language: en-US
In-Reply-To: <udn5sm$12qs5$1@dont-email.me>
 by: Paavo Helde - Mon, 11 Sep 2023 15:20 UTC

11.09.2023 16:49 Bonita Montero kirjutas:
> Am 11.09.2023 um 15:44 schrieb Bonita Montero:
>
>> That's the same as when the static object's constructor throws,
>> i.e. the object will get another try if you get again to the
>> initialization. And if an exception is thrown the context of
>> the definition is left to the next exception handler that you
>> won't operate on a non initialized object.
>> I don't see where's the problem here.
>
> Look at this code:
>
> #include <iostream>
>
> using namespace std;
>
> int main()
> {
>     struct WillReInit
>     {
>         WillReInit()
>         {
>             throw "hello world";
>         }
>     };
>     for( ; ; )
>         try
>         {
>             static WillReInit wi;
>         }
>         catch( char const *str )
>         {
>             cout << str << endl;
>         }
> }
>
>
> Things would be similar if the synchronization would throw, i.e. wri
> would be initialized over and over. So there won't be any accessible
> uninitialized object.

Good, finally some code! Alas, this is not very relevant as it demoes a
local static object, my post which you replied to started with "Dynamic
initialization of a non-local variable with static storage duration..."

Even for local objects, what's the point? If the issue could be resolved
by simply retrying the operation, the C++ implementation could easily do
the same internally and avoid the issue. If the issue cannot be resolved
by a simple retry, then what code should a programmer write, to get the
static initialized? Especially considering that the issue is
non-reproducible and thus cannot be played out or tested. Writing
untestable code to work around non-existing errors is not a healthy way
to spend ones time IMO.

Re: Thread-safe initialization of static objects

<udnfih$14bu0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1437&group=comp.lang.c%2B%2B#1437

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 18:34:25 +0200
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <udnfih$14bu0$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
<udkq3u$koun$1@dont-email.me> <udl2fv$m1ie$1@dont-email.me>
<udn5jc$12oal$1@dont-email.me> <udn5sm$12qs5$1@dont-email.me>
<udnb84$13n78$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 16:34:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="9bf3d5b50b6abadc4d9afd539a9b4fc8";
logging-data="1191872"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18UvqGqd27yReFdHRw+ahCXyrcFirC69n4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:sd1kDspD0hYwFbFX/mmhqcDj/8U=
In-Reply-To: <udnb84$13n78$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Mon, 11 Sep 2023 16:34 UTC

Am 11.09.2023 um 17:20 schrieb Paavo Helde:

> Good, finally some code! Alas, this is not very relevant as it demoes a
> local static object, my post which you replied to started with "Dynamic
> initialization of a non-local variable with static storage duration..."

Then you misunderstood me and talked nonsense. Of course I didn't talk
about global objects, because exceptions make no sense because they
can't be caught in any functional context. It goes without saying.

> Even for local objects, what's the point?
> If the issue could be resolved by simply retrying the operation, ...

If you think spinning would make sense, then you could handle most
system_error errors like that. But that's not how it's designed.

> Especially considering that the issue is non-reproducible and thus
> cannot be played out or tested.

A failing mutex isn't reproducible either; nevertheless there are
system_error exceptions which could be thrown while synchonizing.

Re: Thread-safe initialization of static objects

<udnqhc$160ia$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1438&group=comp.lang.c%2B%2B#1438

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 12:41:31 -0700
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <udnqhc$160ia$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 11 Sep 2023 19:41:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="23a839a520af8f67c5f88d72ed24e588";
logging-data="1245770"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/TG/AqgZ1po/BHF0yXkGPIQ1UIx3JSwoQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:wvZPfXtGnFHTPLbjBLBB8s/hInc=
Content-Language: en-US
In-Reply-To: <udn883$135tl$1@dont-email.me>
 by: Chris M. Thomasson - Mon, 11 Sep 2023 19:41 UTC

On 9/11/2023 7:29 AM, Bonita Montero wrote:
> Am 10.09.2023 um 20:12 schrieb Chris M. Thomasson:
>
>> So, are you suggesting that the C++ standard should be tightly
>> integrated with a given kernel impl? Humm... Strange. POSIX
>> aside for a moment...
>
>
> Not more than it is integrated to the operating system through
> throwing system_error, therby having an operating dependent
> error code which is translated by the operating system (inter-
> nally through strerror() or FormatMessage()).
> So it would be most appropriate to throw system_error with an
> operating system dependent error code and system_category as
> the translator - just like std::mutex does.
>

What if somebody writing C++ wants to be abstract and try to avoid a
particular systems idiosyncrasies?

if std::mutex throws, then shit hit the fan. Not good.

Re: Thread-safe initialization of static objects

<udoico$1d0tr$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1440&group=comp.lang.c%2B%2B#1440

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 12 Sep 2023 04:28:40 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <udoico$1d0tr$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Sep 2023 02:28:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cf301c1035002be99be990832b80cf62";
logging-data="1475515"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/byvPvClfsrSedWPeWC9ZwhemsKtEoGYM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fXrN9LMeTC/SVLzgKxtDp9H6c/Y=
Content-Language: de-DE
In-Reply-To: <udnqhc$160ia$3@dont-email.me>
 by: Bonita Montero - Tue, 12 Sep 2023 02:28 UTC

Am 11.09.2023 um 21:41 schrieb Chris M. Thomasson:

> What if somebody writing C++ wants to be abstract
> and try to avoid a particular systems idiosyncrasies?

Then he would have to ignore specific error codes and
just take the what() in the system_error object.

Re: Thread-safe initialization of static objects

<VlRLM.1202$HpPd.216@fx03.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1441&group=comp.lang.c%2B%2B#1441

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer02.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx03.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<fLrLM.1141591$mPI2.986632@fx15.iad> <udm5rf$u6g6$1@dont-email.me>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <udm5rf$u6g6$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 163
Message-ID: <VlRLM.1202$HpPd.216@fx03.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Tue, 12 Sep 2023 03:58:45 UTC
Date: Mon, 11 Sep 2023 23:58:36 -0400
X-Received-Bytes: 7783
 by: Pavel - Tue, 12 Sep 2023 03:58 UTC

Chris M. Thomasson wrote:
> On 9/10/2023 3:50 PM, Pavel wrote:
>> Richard Damon wrote:
>>> On 9/10/23 1:57 AM, Bonita Montero wrote:
>>>> Am 09.09.2023 um 22:37 schrieb Richard Damon:
>>>>
>>>>> The Standard defines the final results that must happen
>>>>> (or possibilities that can happen in some cases).
>>>>
>>>> The standards also should consider side effects as in this example
>>>> when a static initialization would fail because of a synchronization
>>>> error.
>>>>
>>> You don't seem to understand that sincd it CAN be done in a way that
>>> always works, any method that doesn't always work is just WRONG and
>>> non-conforming.
>>>
>>> I guess you think that 1 + 1 must be allowed to be 1 in case of
>>> "synchronization errors".
>>>
>>> Static Initialization has DEFINED behavior, and that behavior must be
>>> honored, and the implementation do what is need to make that happen.
>>>
>>> Methods have been shown to do it (perhaps less performant than this
>>> is some conditions),
>> Actually, I think there should be always a better-performing method to
>> implement C++ static initialization than using windows or pthread
>> mutex -- e.g. using a specialized control like those used for
>> call_once implementation -- at least on UNIX or Windows.
>>
>> This is because IMHO mutex API is a textbook case of feature bloat on
>> both platforms.
>>
>> E.g. in standard UNIX (former POSIX), you can have recursive / robust
>> / shared / errorcheck mutex (not all mutually exclusive) and who knows
>> what else. pthread_mutex_lock shall be able to deal with either
>> combination and the feature-check code makes (at least the current)
>> implementation quite messy, with multiple dispatches on the same
>> condition.
>>
>> On Windows, the number of options is less; but, to compensate for that
>> :-), a mutex is always recursive plus wait functions have to know how
>> to deal with inter-process mutexes because any handle passed to them
>> can turn out to be of an inter-process mutex (or even not a mutex at
>> all). Therefore, I do not think their use for static initialization
>> (that does not require either recursive or inter-process lock) even
>> could be optimal.
>
> I might be missing your point here. Humm... Even though POSIX has all of
> these different types of mutexs, we can use them by organization.
The point is that, even assuming that all types of mutices are very well
organized in the implementation, some dispatch of control still has to
occur when one calls "pthread_mutex_lock" because it is a single entry
point for locking a mutex with any combination of features. Given that
locking of a non-contended mutex is supposed to be (and in fact is, on
current Linux) very cheap (but not necessarily same-cheap if the mutex
is recursive :-) ), the relative cost of this dispatch is not guaranteed
to be negligible (even if that dispatch is implemented via a single
extra level of indirection).

Further, I am unsure if these features actually *can* be very well
organized because not all features of mutices are mutually exclusive (no
pun intended) so a single extra level of indirection might not be enugh.
As an example, mutexattr type can be one of

PTHREAD_MUTEX_NORMAL PTHREAD_MUTEX_ERRORCHECK PTHREAD_MUTEX_RECURSIVE
PTHREAD_MUTEX_DEFAULT

but each of these can be additionally either robust or non-robust (and,
pthread_mutex_lock is supposed to behave differently for some
combinations of type and robustness). Unless of course we dispatch to a
cartesian product of options (which is not impossible, but see below).

And, lastly, the above are all hypotheticals and the actual code (see
e.g. https://codebrowser.dev/glibc/glibc/nptl/pthread_mutex_lock.c.html
) is slightly messier than the best organized implementation possible.
From practical perspective, I would expect that someone implementing a
thread-safe static initialization in a C++ compiler has their mouth full
with the tasks other than improving the existing pthread_mutex (or
pthread_once) implementation as a distraction; at most (I would
speculate), they would take a quick (~5 min) look into the API and the
available code of the existing established synchronization primitives
and decide which one is likely to better fit their spec and be faster
as-is to use to implement that pesky initialization spec. In this
scenario, I would guess that pthread_once_t would win the beauty contest
and get selected.

And, sure enough, (likely due to no feature bloat) the *existing*
pthread_once implementation code is much cleaner (see
https://codebrowser.dev/glibc/glibc/nptl/pthread_once.c.html) and at
first glance should be measurably faster.

I guess, instead of guessing, (no pun untended again), we could just
disassemble some static initialization and see how it's done in, say,
gcc. Maybe later...

> So,
> wrt windows, an intra-process mutex can be a CRITICAL_SECTION. Or an
> inter-process as a mutex HANDLE.
>
> https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createmutexexa
>
>
> Wrt the inter-process route we may need to deal with WAIT_ABANDONED, or
> EOWNERDEAD wrt POSIX. So we create different types:
>
>
> struct intra_process_mutex
> {
>     CRITICAL_SECTION m_os_lock;
> };
>
>
> struct inter_process_mutex
> {
>     HANDLE m_os_lock;
> };
>
> struct inter_process_mutex_robust
> {
>     HANDLE m_os_lock;
> };
>
>
>
> These simple types can be rather easy to reason about. Wrt POSIX, the
> different types would be:
>
>
> struct intra_process_mutex
> {
>     pthread_mutex_t m_os_lock;
> };
>
>
> struct inter_process_mutex
> {
>     pthread_mutex_t m_os_lock;
> };
>
> struct inter_process_mutex_robust
> {
>     pthread_mutex_t m_os_lock;
> };
>
>
> The point is trying to organize things a bit here.
>
> Sound somewhat decent?
>
>
>>
>>> so it is possible, so you can't say the Standard is asking for
>>> impossible behavior, thus any "optimizations" that don't meet that
>>> defined behavior are just WRONG.
>>>
>>> Saying something wrong must be made right is just WRONG, so you are
>>> WRONG in your claim.
>>>
>>> PERIOD.
>>
>

Re: Thread-safe initialization of static objects

<udotj5$1e8do$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1442&group=comp.lang.c%2B%2B#1442

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Mon, 11 Sep 2023 22:39:49 -0700
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <udotj5$1e8do$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 12 Sep 2023 05:39:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb09f42ffaab52f106681a209f7f91e6";
logging-data="1515960"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/IsG/zEtLgpJKjaXTszvTgLVTtml7SPpE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Tagj6DV3UrpMIl1nMsnArmDG3/8=
Content-Language: en-US
In-Reply-To: <udoico$1d0tr$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 12 Sep 2023 05:39 UTC

On 9/11/2023 7:28 PM, Bonita Montero wrote:
> Am 11.09.2023 um 21:41 schrieb Chris M. Thomasson:
>
>> What if somebody writing C++ wants to be abstract
>> and try to avoid a  particular systems idiosyncrasies?
>
> Then he would have to ignore specific error codes and
> just take the what() in the system_error object.
>

what() = shit hit the fan...

Re: Thread-safe initialization of static objects

<udpbun$1gf8c$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1445&group=comp.lang.c%2B%2B#1445

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 12 Sep 2023 11:44:56 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <udpbun$1gf8c$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Sep 2023 09:44:55 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cf301c1035002be99be990832b80cf62";
logging-data="1588492"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ucfhn25m8KzeVi3xIm3CpIeLlq1Af8eI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2k6D2Dt8oe+gH2YHQQ0SHRWRSIk=
In-Reply-To: <udotj5$1e8do$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Tue, 12 Sep 2023 09:44 UTC

Am 12.09.2023 um 07:39 schrieb Chris M. Thomasson:

> On 9/11/2023 7:28 PM, Bonita Montero wrote:

>> Then he would have to ignore specific error codes and
>> just take the what() in the system_error object.

> what() = shit hit the fan...

You seem to be psychotic, but I'll describe it anyway. If you have
a system_error and it is created with a system_category the error
code is converted through streror() (or the thread -safe variant)
on Posix and with FormatMessage() in Windows.
With MSVC there was a bug which I filed in forum for MSVC that
system_category() does not honor the current threads's locale
when translating the error code with FormatMessage(). They
said they'll fix that and actually it was fixed with the next
update.

Re: Thread-safe initialization of static objects

<udqatg$1mar3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1451&group=comp.lang.c%2B%2B#1451

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 12 Sep 2023 11:33:19 -0700
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <udqatg$1mar3$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Sep 2023 18:33:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb09f42ffaab52f106681a209f7f91e6";
logging-data="1780579"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18d2mAj5KDUSUZRdcpMfXO9MrSKoOyAGHU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:1ToBO2LGg78d4KmnqlLW6BWlgGM=
Content-Language: en-US
In-Reply-To: <udpbun$1gf8c$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 12 Sep 2023 18:33 UTC

On 9/12/2023 2:44 AM, Bonita Montero wrote:
> Am 12.09.2023 um 07:39 schrieb Chris M. Thomasson:
>
>> On 9/11/2023 7:28 PM, Bonita Montero wrote:
>
>>> Then he would have to ignore specific error codes and
>>> just take the what() in the system_error object.
>
>> what() = shit hit the fan...
>
> You seem to be psychotic, but I'll describe it anyway.

If a static initialization fails, things have gone horribly wrong.
What's your big beef with static initialization?

> If you have
> a system_error and it is created with a system_category the error
> code is converted through streror() (or the thread -safe variant)
> on Posix and with FormatMessage() in Windows.
> With MSVC there was a bug which I filed in forum for MSVC that
> system_category() does not honor the current threads's locale
> when translating the error code with FormatMessage(). They
> said they'll fix that and actually it was fixed with the next
> update.
>

Re: Thread-safe initialization of static objects

<udqbg3$1mdv6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1452&group=comp.lang.c%2B%2B#1452

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 12 Sep 2023 20:43:15 +0200
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <udqbg3$1mdv6$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Sep 2023 18:43:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="cf301c1035002be99be990832b80cf62";
logging-data="1783782"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18xSFAsqL9LnIq5Bi5byamgRAw/PEk2+og="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:RfYFFMBNM+jVdazG0Iv2hT1HzjI=
Content-Language: de-DE
In-Reply-To: <udqatg$1mar3$1@dont-email.me>
 by: Bonita Montero - Tue, 12 Sep 2023 18:43 UTC

Am 12.09.2023 um 20:33 schrieb Chris M. Thomasson:
> On 9/12/2023 2:44 AM, Bonita Montero wrote:
>> Am 12.09.2023 um 07:39 schrieb Chris M. Thomasson:
>>
>>> On 9/11/2023 7:28 PM, Bonita Montero wrote:
>>
>>>> Then he would have to ignore specific error codes and
>>>> just take the what() in the system_error object.
>>
>>> what() = shit hit the fan...
>>
>> You seem to be psychotic, but I'll describe it anyway.
>
> If a static initialization fails, things have gone horribly wrong.
> What's your big beef with static initialization?

At this point we weren't talking about static initialization but about
the properties of system_error. But static initialization is less likely
to go wrong because of a synchronization error but more likely because
the constructor of the static object throws. As I've shown with my code
in this thread the object is left uninitialized then and if the code
reaches the initialization again it gets another chance.

Re: Thread-safe initialization of static objects

<udqq8u$1p3q6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1453&group=comp.lang.c%2B%2B#1453

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 12 Sep 2023 15:55:25 -0700
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <udqq8u$1p3q6$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Sep 2023 22:55:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0c8975978d1b140b162b15c04597b0b6";
logging-data="1871686"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FHao0Gx0fi90Mxk2eEtP3uvMEW8DG+EQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:PfoSV0bcsfhwLxbH4yRrTJiYkRE=
In-Reply-To: <udqbg3$1mdv6$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Tue, 12 Sep 2023 22:55 UTC

On 9/12/2023 11:43 AM, Bonita Montero wrote:
> Am 12.09.2023 um 20:33 schrieb Chris M. Thomasson:
>> On 9/12/2023 2:44 AM, Bonita Montero wrote:
>>> Am 12.09.2023 um 07:39 schrieb Chris M. Thomasson:
>>>
>>>> On 9/11/2023 7:28 PM, Bonita Montero wrote:
>>>
>>>>> Then he would have to ignore specific error codes and
>>>>> just take the what() in the system_error object.
>>>
>>>> what() = shit hit the fan...
>>>
>>> You seem to be psychotic, but I'll describe it anyway.
>>
>> If a static initialization fails, things have gone horribly wrong.
>> What's your big beef with static initialization?
>
> At this point we weren't talking about static initialization but about
> the properties of system_error. But static initialization is less likely
> to go wrong because of a synchronization error but more likely because
> the constructor of the static object throws. As I've shown with my code
> in this thread the object is left uninitialized then and if the code
> reaches the initialization again it gets another chance.
>

You mean where you wrote:

"The mutex constructor
is noexcept, so mutexes always must be created on their first use."

Well... Why do you state that mutexes must always be created on their
first use? Hummm. Just because you say so, does not make it true at all.

Re: Thread-safe initialization of static objects

<udqqat$1p3q6$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1454&group=comp.lang.c%2B%2B#1454

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 12 Sep 2023 15:56:28 -0700
Organization: A noiseless patient Spider
Lines: 36
Message-ID: <udqqat$1p3q6$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Sep 2023 22:56:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0c8975978d1b140b162b15c04597b0b6";
logging-data="1871686"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/XekqQGpSKkYGrABcoWIfPyPltDOxkS18="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:5zBEmZgRc1A+m5EIkHVQvrH8HjY=
Content-Language: en-US
In-Reply-To: <udqq8u$1p3q6$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 12 Sep 2023 22:56 UTC

On 9/12/2023 3:55 PM, Chris M. Thomasson wrote:
> On 9/12/2023 11:43 AM, Bonita Montero wrote:
>> Am 12.09.2023 um 20:33 schrieb Chris M. Thomasson:
>>> On 9/12/2023 2:44 AM, Bonita Montero wrote:
>>>> Am 12.09.2023 um 07:39 schrieb Chris M. Thomasson:
>>>>
>>>>> On 9/11/2023 7:28 PM, Bonita Montero wrote:
>>>>
>>>>>> Then he would have to ignore specific error codes and
>>>>>> just take the what() in the system_error object.
>>>>
>>>>> what() = shit hit the fan...
>>>>
>>>> You seem to be psychotic, but I'll describe it anyway.
>>>
>>> If a static initialization fails, things have gone horribly wrong.
>>> What's your big beef with static initialization?
>>
>> At this point we weren't talking about static initialization but about
>> the properties of system_error. But static initialization is less likely
>> to go wrong because of a synchronization error but more likely because
>> the constructor of the static object throws. As I've shown with my code
>> in this thread the object is left uninitialized then and if the code
>> reaches the initialization again it gets another chance.
>>
>
> You mean where you wrote:
>
> "The mutex constructor
> is noexcept, so mutexes always must be created on their first use."
>
> Well... Why do you state that mutexes must always be created on their
> first use? Hummm. Just because you say so, does not make it true at all.

The subject is about static initialization, and the sync that the impl
uses to get that does does not have to follow your rules at all.

Re: Thread-safe initialization of static objects

<uds0qa$22qfj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1455&group=comp.lang.c%2B%2B#1455

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Wed, 13 Sep 2023 11:53:16 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uds0qa$22qfj$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 13 Sep 2023 09:53:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b749d706f1ecdca6a3ed9b5055e972f1";
logging-data="2189811"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18x8fyyx3INf/zu4cdne2EnOP0iusPfEbk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9NyO9BokuDtg/YI/68jhb3viYbA=
Content-Language: de-DE
In-Reply-To: <udqq8u$1p3q6$1@dont-email.me>
 by: Bonita Montero - Wed, 13 Sep 2023 09:53 UTC

Am 13.09.2023 um 00:55 schrieb Chris M. Thomasson:

> Well... Why do you state that mutexes must always be created on their
> first use? Hummm. Just because you say so, does not make it true at all.

Of course, because the mutex constructor is noexcept. The interesting
thing is that the situation can arise where several threads simultan-
eously try to create the binary semaphore associated with the mutex
and only one ultimately assigns this semaphore to the mutex. And if
the other threads notice this afterwards, they have to return the
semaphore to the kernel. Since the mutex constructor is noexcept
there is no other way for an implementation to handle this.

Re: Thread-safe initialization of static objects

<udtg9s$2aqb5$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1456&group=comp.lang.c%2B%2B#1456

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Wed, 13 Sep 2023 16:23:39 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <udtg9s$2aqb5$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
<uds0qa$22qfj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 13 Sep 2023 23:23:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="41554d4f560ec25558d7e636110c1df7";
logging-data="2451813"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19J7jOnM3OoRlJF/UR6jJFhf9n9yKBhyZk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:XfQ8hhif+xl7pFLuQjxb5kelKag=
Content-Language: en-US
In-Reply-To: <uds0qa$22qfj$1@dont-email.me>
 by: Chris M. Thomasson - Wed, 13 Sep 2023 23:23 UTC

On 9/13/2023 2:53 AM, Bonita Montero wrote:
> Am 13.09.2023 um 00:55 schrieb Chris M. Thomasson:
>
>> Well... Why do you state that mutexes must always be created on their
>> first use? Hummm. Just because you say so, does not make it true at all.
>
> Of course, because the mutex constructor is noexcept. The interesting
> thing is that the situation can arise where several threads simultan-
> eously try to create the binary semaphore associated with the mutex
> and only one ultimately assigns this semaphore to the mutex. And if
> the other threads notice this afterwards, they have to return the
> semaphore to the kernel. Since the mutex constructor is noexcept
> there is no other way for an implementation to handle this.
>

How do you think futexes work when they are completely addressed based?
Nothing to create. I guess you are not that familiar with them. So be it.

Re: Thread-safe initialization of static objects

<uduimg$2imqi$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=1458&group=comp.lang.c%2B%2B#1458

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Thu, 14 Sep 2023 11:10:42 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <uduimg$2imqi$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
<udk0hm$h1e9$3@dont-email.me> <udl0ti$lp5v$4@dont-email.me>
<udn883$135tl$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
<uds0qa$22qfj$1@dont-email.me> <udtg9s$2aqb5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 14 Sep 2023 09:10:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="35912dbc17c9d5e20044546162754b78";
logging-data="2710354"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eSV8c7x9MN+3uI9Xafp4hK9Z7L9hK1SM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:4ki3nSsPJsVoMnlD7QInlGJvzJs=
In-Reply-To: <udtg9s$2aqb5$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 14 Sep 2023 09:10 UTC

Am 14.09.2023 um 01:23 schrieb Chris M. Thomasson:

> How do you think futexes work when they are completely addressed based?
> Nothing to create. I guess you are not that familiar with them. So be it.

Why should a futex be uses on static initializaton, where the
mutex is used only once by the thread which initializes the
object and there's not much likehood of contention and even
if, this contention happens only once per competing thread ?


devel / comp.lang.c++ / Re: Thread-safe initialization of static objects

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor