Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Never make anything simple and efficient when a way can be found to make it complex and wonderful.


devel / comp.lang.c++ / 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

<uebnc1$293m3$5@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 10:50:10 +0200
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <uebnc1$293m3$5@dont-email.me>
References: <udafjf$2joeq$1@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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<EjoNM.17221$DXgc.9861@fx36.iad> <ue5tfc$7pns$1@dont-email.me>
<zPGNM.14021$BMnd.11871@fx04.iad> <ue7f6g$frod$2@dont-email.me>
<LWINM.13017$ZkX3.12109@fx09.iad> <ue8mn0$q534$4@dont-email.me>
<uY5OM.30730$Yxl8.13078@fx14.iad> <ueb3sb$2638l$6@dont-email.me>
<uebaoh$271en$8@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 08:50:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2395843"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+h7P0/hOlNP7Ot7VifkSx2fjX+d/79n4w="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ms/XIWJa7vid8hfiBriQI4RYTC8=
In-Reply-To: <uebaoh$271en$8@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Tue, 19 Sep 2023 08:50 UTC

Am 19.09.2023 um 07:14 schrieb Chris M. Thomasson:

> I assume going to "sleep" means waiting in the kernel on a slow path.
> Otherwise, humm... Are you talking about user logic that sleeps for a
> second or two? Why should that matter at all? The impl shall arrange
> things such that there is no deadlock. Let me guess Bonita, you think
> that user logic that waits for infinity while its trying to initialize
> itself should be handled in the std? Humm... Not sure about you.

You often seem confused.

Re: Thread-safe initialization of static objects

<ueboet$29a2b$1@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 02:08:44 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ueboet$29a2b$1@dont-email.me>
References: <udafjf$2joeq$1@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> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 09:08:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2402379"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+23dvhESblkFVkN6gbAg60TaJg6nfhNmg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:EZYdydPANNPOcBoRBbPyZ6WsIMs=
Content-Language: en-US
In-Reply-To: <uebn4f$293m3$2@dont-email.me>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 09:08 UTC

On 9/19/2023 1:46 AM, Bonita Montero wrote:
> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>
>>> I've shown that static initialization actually uses a mutex per object.
>
>> Really?
>
> Here, a third time the code for you:
[snip code]

That does mean every impl must use a mutex per object wrt static
initialization. Just because you claim that they do, does not make it so.

Re: Thread-safe initialization of static objects

<uebq3e$29k5u$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 11:36:46 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uebq3e$29k5u$1@dont-email.me>
References: <udafjf$2joeq$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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<ueboet$29a2b$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 09:36:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2412734"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/fV1bx67xBfvy3Y1TBr+9/QmzPopOvpHM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:A+FOSQKg86cMv5CsYhs2J2+Zrvc=
In-Reply-To: <ueboet$29a2b$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Tue, 19 Sep 2023 09:36 UTC

Am 19.09.2023 um 11:08 schrieb Chris M. Thomasson:

> That does mean every impl must use a mutex per object wrt static
> initialization. Just because you claim that they do, does not make
> it so.

I've run the code with MSVC, libstdc++ and libc++, and with all
implementations the code runs about a second, so there's no central
mutex for all static initializations, but a mutex per static object.
I've told that multiple times and you didn't understand that.

Re: Thread-safe initialization of static objects

<mUfOM.25777$ZkX3.20078@fx09.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx09.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> <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> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me> <ueboet$29a2b$1@dont-email.me>
<uebq3e$29k5u$1@dont-email.me>
From: Richard@Damon-Family.org (Richard Damon)
In-Reply-To: <uebq3e$29k5u$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 22
Message-ID: <mUfOM.25777$ZkX3.20078@fx09.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: Tue, 19 Sep 2023 07:48:34 -0400
X-Received-Bytes: 2630
 by: Richard Damon - Tue, 19 Sep 2023 11:48 UTC

On 9/19/23 5:36 AM, Bonita Montero wrote:
> Am 19.09.2023 um 11:08 schrieb Chris M. Thomasson:
>
>> That does mean every impl must use a mutex per object wrt static
>> initialization. Just because you claim that they do, does not make
>> it so.
>
> I've run the code with MSVC, libstdc++ and libc++, and with all
> implementations the code runs about a second, so there's no central
> mutex for all static initializations, but a mutex per static object.
> I've told that multiple times and you didn't understand that.
>
>

IF there is a Mutex per individual object, where is it? Show the call to
make them.

You are just makeing an ASS out of yourself (and not us) because you
ASS-U-ME about how it "must" work.

Just because you are too dense to see other options, doesn't mean they
don't exist.

Re: Thread-safe initialization of static objects

<uec35s$2b8an$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 14:11:40 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uec35s$2b8an$1@dont-email.me>
References: <udafjf$2joeq$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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<ueboet$29a2b$1@dont-email.me> <uebq3e$29k5u$1@dont-email.me>
<mUfOM.25777$ZkX3.20078@fx09.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 12:11:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2466135"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gWzBZCaWFoNS5etKGm7cZI3IdZpZmMf4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:LBAQXqDLN4e0iAxkKSGlvnuRBJ0=
In-Reply-To: <mUfOM.25777$ZkX3.20078@fx09.iad>
Content-Language: de-DE
 by: Bonita Montero - Tue, 19 Sep 2023 12:11 UTC

Am 19.09.2023 um 13:48 schrieb Richard Damon:

> IF there is a Mutex per individual object, where is it? Show the call to
> make them.

I've proven that because multiple static initializations of
different objects run in parallel. Otherwise the code would
have run 100 seconds.
It makes sense to have a mutex per static object because with
that you can also have recursive static inizialization, which
would otherwise be not possible.

Re: Thread-safe initialization of static objects

<uec8e5$2c9ri$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 15:41:24 +0200
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <uec8e5$2c9ri$1@dont-email.me>
References: <udafjf$2joeq$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> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me> <ueboet$29a2b$1@dont-email.me>
<uebq3e$29k5u$1@dont-email.me> <mUfOM.25777$ZkX3.20078@fx09.iad>
<uec35s$2b8an$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 13:41:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2500466"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gJNZVma3N/LItu8EJL+oX6r0GaVQcd70="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nG3SdWi3v/9LYpl6kdwpyx0tBOw=
In-Reply-To: <uec35s$2b8an$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Tue, 19 Sep 2023 13:41 UTC

Am 19.09.2023 um 14:11 schrieb Bonita Montero:

> I've proven that because multiple static initializations of
> different objects run in parallel. Otherwise the code would
> have run 100 seconds.

I've extended the code to show that there are 100 different
static initializations per thread:

#include <iostream>
#include <utility>
#include <vector>
#include <thread>
#include <syncstream>

using namespace std;

int main()
{ struct InitSleep
{
InitSleep()
{
this_thread::sleep_for( 1s );
}
};
constexpr unsigned N_THREADS = 100;
auto unroll = []<size_t ... Indices>( index_sequence<Indices ...>, auto
fn )
{
(fn.template operator ()<Indices>(), ...);
};
vector<jthread> threads;
threads.reserve( N_THREADS );
unroll( make_index_sequence<N_THREADS>(),
[&]<size_t T>()
{
threads.emplace_back( []( auto )
{
static InitSleep is;
osyncstream( cout ) << (void *)&is << endl;
}, integral_constant<size_t, T>() );
} );
}

If you run the code you can see that each static object has a unique
address, different from each other.

Re: Thread-safe initialization of static objects

<1GhOM.7399$H0Ge.6907@fx05.iad>

  copy mid

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

  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!fx05.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: scott@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
Lines: 12
Message-ID: <1GhOM.7399$H0Ge.6907@fx05.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 19 Sep 2023 13:49:49 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 19 Sep 2023 13:49:49 GMT
X-Received-Bytes: 1388
 by: Scott Lurndal - Tue, 19 Sep 2023 13:49 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>
>>> I've shown that static initialization actually uses a mutex per object.
>
>> Really?
>
>Here, a third time the code for you:

This code doesn't show any mutex at all.

Disassemble the code and find the synchronization object.

Re: Thread-safe initialization of static objects

<uecac1$2cj86$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 16:14:25 +0200
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uecac1$2cj86$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 14:14:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2510086"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19zT1svyoWxKdItZVU0+NkZuIvB72TF1M8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:n2BRWN/l1x9n+WpPOXpZap1IY+A=
Content-Language: de-DE
In-Reply-To: <1GhOM.7399$H0Ge.6907@fx05.iad>
 by: Bonita Montero - Tue, 19 Sep 2023 14:14 UTC

Am 19.09.2023 um 15:49 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>>
>>>> I've shown that static initialization actually uses a mutex per object.
>>
>>> Really?
>>
>> Here, a third time the code for you:
>
> This code doesn't show any mutex at all.

It is guaranteed that if multiple threads go through a line of code
with static initialization, only one thread will actually initialize
the static object and others will sleep meanwhile. This can't be
handled without something that works like a mutex. It is irrelevant
whether a std::mutex or a native mutex of the operating system is
used. Others here have understood that this is the only way it works,
the point of the discussion was simply whether exactly one mutex is
responsible for all static initializations, which would make it
possible to get through almost always without a malfunction, or
whether it would be more static Initialization there is a mutex.
I have proven the latter with my code.
So again: it is guaranteed that static initialization is thread-safe.
The standard also says that if more than one thread wants to initialize
statically, all others do not do so and ultimately sleep until the
initialization is complete. Please tell me how this should work
differently than with a mutex

> Disassemble the code and find the synchronization object.

Idiot.

Re: Thread-safe initialization of static objects

<20230919073225.221@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 16:41:48 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <20230919073225.221@kylheku.com>
References: <udafjf$2joeq$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> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me> <ueboet$29a2b$1@dont-email.me>
<uebq3e$29k5u$1@dont-email.me> <mUfOM.25777$ZkX3.20078@fx09.iad>
<uec35s$2b8an$1@dont-email.me>
Injection-Date: Tue, 19 Sep 2023 16:41:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="78a1cbf526ee5626f6ff8689cdc8787c";
logging-data="2570035"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18O30bJi5kDWwKpjb4eLkkwpC1DB05zADg="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:+Wp1618JT28wftBcTAQFpYxbYAw=
 by: Kaz Kylheku - Tue, 19 Sep 2023 16:41 UTC

On 2023-09-19, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 19.09.2023 um 13:48 schrieb Richard Damon:
>
>> IF there is a Mutex per individual object, where is it? Show the call to
>> make them.
>
> I've proven that because multiple static initializations of
> different objects run in parallel. Otherwise the code would
> have run 100 seconds.
> It makes sense to have a mutex per static object because with
> that you can also have recursive static inizialization, which
> would otherwise be not possible.

I don't suspect you can have a recursive initialization that isn't
erroneous.

If an object is in progress of being initialized, I think
the program must prevent the re-entry of that.

I'm surprised that you don't consider the possibility of
one mutex per "basic block":

Given:

{
static this x = f();
static that y = g();
// ...

}

why couldn't we have a single hidden mutex serializing both
initializations, rather than two mutexes?

If there is no conditional which separates the initialization of the
static objects, it seems they can be handled as an aggregate.

If there are separate mutexes for calling f() and g(), what
good does that do. If g() ends up recursing back to the above
scope, it will go past the x = f() initialization, which
is complete. That is well and good, but it will necessarily
hit the y = g() on also, which is bad.

There is no control flow branch which separates the two;
if one is executed, the other is.

What do you think?

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Thread-safe initialization of static objects

<20230919094617.529@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 16:53:12 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 55
Message-ID: <20230919094617.529@kylheku.com>
References: <udafjf$2joeq$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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<EjoNM.17221$DXgc.9861@fx36.iad> <ue5tfc$7pns$1@dont-email.me>
<zPGNM.14021$BMnd.11871@fx04.iad> <ue7f6g$frod$2@dont-email.me>
<ue7gdm$fumm$4@dont-email.me> <ue7hc3$g7tm$1@dont-email.me>
<ue7r4j$i3u1$1@dont-email.me> <ue8mid$q534$2@dont-email.me>
<O9XNM.16067$JX2f.12159@fx13.iad> <20230918110147.326@kylheku.com>
<uea42g$1sn0e$2@dont-email.me> <20230918123203.723@kylheku.com>
<ueb3q5$2638l$5@dont-email.me> <20230918205859.263@kylheku.com>
<uebn7l$293m3$3@dont-email.me>
Injection-Date: Tue, 19 Sep 2023 16:53:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="78a1cbf526ee5626f6ff8689cdc8787c";
logging-data="2570035"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ig5BwYPR1Kp0UmUI9HodhAv6wY5TIYiE="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:YOY272iMHnj6wrW8+meVezt8Slo=
 by: Kaz Kylheku - Tue, 19 Sep 2023 16:53 UTC

On 2023-09-19, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 19.09.2023 um 06:05 schrieb Kaz Kylheku:
>
>> You /seemed/ to be claiming that such an arrangement cannot deadlock.
>> Whether or not, I'm showing above how it can.
>> 1. One static initialization can be nested inside another,
>> such that the calling thread momentarily owns both mutexes.
>
> Then two mutexes are used.
>
>> 3. Thus, two threads can nest the same pair of initializations
>> in opposite order.
>
> If multiple mutexes are used that's actually not a problem.

Oh, it's a problem.

> And as I've shown there's a mutex per static initialization.

That's what creates the posssibility of deadlock. You do understand
that if two threads stepwise try to lock the same pair of mutexes in
opposite order, you get deadlock?

Thread A Thread B
| |
x.lock(); y.lock();
| |
y.lock() x.lock();

A is waiting for B to release y, which is waiting for A to release x.

You do understand that the mutex has to be held across
the initialization, right? Such that in "int x = f()",
the mutex is locked before we check the "__x_inited" flag.
If it is false, we call f(), update x, and then set __x_inited
true, and releases the mutex.

Thus, if initializations happen to nest, a thread can hold multiple
such mutexes.

This might not be a problem in the sense that if there is only one
thread, everything is fine, so that it's only a threads issue.

All the programs I can think of which trigger this problem also have a
problem if there exists just one thread doing all the initializing;
those repro programs dubiously recurse among initializations.

But, nevertheless, it's something that deadlock-detecting mutexes
could catch, whether for one thread, or multiple.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Thread-safe initialization of static objects

<uecn0t$2f5ud$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 19:50:20 +0200
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <uecn0t$2f5ud$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
<uds0qa$22qfj$1@dont-email.me> <udtg9s$2aqb5$1@dont-email.me>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<ueboet$29a2b$1@dont-email.me> <uebq3e$29k5u$1@dont-email.me>
<mUfOM.25777$ZkX3.20078@fx09.iad> <uec35s$2b8an$1@dont-email.me>
<20230919073225.221@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 17:50:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2594765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+LhfOptSICip6SVaqNVy/nB8dwbcl6jNI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:7a5ZbNcH8hJ04Q/y+4+pF4Qx7IY=
In-Reply-To: <20230919073225.221@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 19 Sep 2023 17:50 UTC

Am 19.09.2023 um 18:41 schrieb Kaz Kylheku:

> I don't suspect you can have a recursive initialization that isn't
> erroneous.

Recursive initialization of static object simply works if you have
a mutex per object. I'm sure the standard requires that, otherwise
you'd run into problems. Actually the three mentioned implementations
support that because there's a mutex per objec.t

> If an object is in progress of being initialized, I think
> the program must prevent the re-entry of that.

That's a further flag.

> I'm surprised that you don't consider the possibility of
> one mutex per "basic block":

That's also a way to handle this, but I think the most elegant
way would be to have a lock-free stack of mutexes as a pool and
the mutex is given back to the pool by the last contender.

> why couldn't we have a single hidden mutex serializing both
> initializations, rather than two mutexes?

That's transparent if the standard handles it this way or not.

Re: Thread-safe initialization of static objects

<uecn60$2f5ud$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 19:53:04 +0200
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <uecn60$2f5ud$2@dont-email.me>
References: <udafjf$2joeq$1@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> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <ue7gdm$fumm$4@dont-email.me>
<ue7hc3$g7tm$1@dont-email.me> <ue7r4j$i3u1$1@dont-email.me>
<ue8mid$q534$2@dont-email.me> <O9XNM.16067$JX2f.12159@fx13.iad>
<20230918110147.326@kylheku.com> <uea42g$1sn0e$2@dont-email.me>
<20230918123203.723@kylheku.com> <ueb3q5$2638l$5@dont-email.me>
<20230918205859.263@kylheku.com> <uebn7l$293m3$3@dont-email.me>
<20230919094617.529@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 17:53:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2594765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18mLL5U/Z1I7b99m6mKH7/1NTWFRojFaWk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yK4ZB8d71W4BRw4+p910fRcMa9s=
In-Reply-To: <20230919094617.529@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 19 Sep 2023 17:53 UTC

Am 19.09.2023 um 18:53 schrieb Kaz Kylheku:

> That's what creates the posssibility of deadlock. You do understand
> that if two threads stepwise try to lock the same pair of mutexes in
> opposite order, you get deadlock?
>
> Thread A Thread B
> | |
> x.lock(); y.lock();
> | |
> y.lock() x.lock();
>
> A is waiting for B to release y, which is waiting for A to release x.

Show me the code with static initialization that produces a deadlock.
That would be possible with nested initialization, but when you nest
you have always the same order, so this actually wouldn't give a
deadlock.

Re: Thread-safe initialization of static objects

<ueco83$2fd1j$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: eesnimi@osa.pri.ee (Paavo Helde)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 21:11:15 +0300
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <ueco83$2fd1j$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad>
<3ba58128-f2f5-4639-8b9d-606782c2b486n@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 19 Sep 2023 18:11:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8a2247f1def7c429a669adfa939dfd6b";
logging-data="2602035"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+XMOvwwXreVMMT9rPigC8l4BLpjcKtg98="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:b6TXXCUJW2zoaFsQSqkexHFxdv4=
In-Reply-To: <3ba58128-f2f5-4639-8b9d-606782c2b486n@googlegroups.com>
Content-Language: en-US
 by: Paavo Helde - Tue, 19 Sep 2023 18:11 UTC

19.09.2023 19:55 Michael S kirjutas:
> On Tuesday, September 19, 2023 at 4:50:05 PM UTC+3, Scott Lurndal wrote:
>> Bonita Montero <Bonita....@gmail.com> writes:
>>> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>>>
>>>>> I've shown that static initialization actually uses a mutex per object.
>>>
>>>> Really?
>>>
>>> Here, a third time the code for you:
>> This code doesn't show any mutex at all.
>>
>> Disassemble the code and find the synchronization object.
>
> I did a disassembling.
> https://godbolt.org/z/rM6Tf3Y87
>
> Bonita is correct in principle if not in details.
> May be she is correct in details too, I did not read all her posts.
>
> Compiler does emit one specialized mutex per static object.
> In case of LLVM such mutex consists of pair of 8-bit flags
> that appear to encode 3 or 4 possible states. The flags
> are updated under protection of global heavyweight mutex.
> Details can be found for example here:
> https://opensource.apple.com/source/libcppabi/libcppabi-14/src/cxa_guard.cxx
>
> I would think that other C++ compilers have similar mechanisms.

Nobody has denied there must be some synchronization in static
initialization. Bonita would be right only if there is some possibility
of failure when updating those flags.

Re: Thread-safe initialization of static objects

<uecr23$2g167$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.Montero@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 20:59:15 +0200
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <uecr23$2g167$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad>
<3ba58128-f2f5-4639-8b9d-606782c2b486n@googlegroups.com>
<ueco83$2fd1j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 18:59:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="85b9ebaf81ad877fb9605894b3bc8446";
logging-data="2622663"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18iod76MC550Cj3BqnQTSOFPxWeOFaELHw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:wklFPKZZdRyuUnnLs+/A4bm2aL8=
Content-Language: de-DE
In-Reply-To: <ueco83$2fd1j$1@dont-email.me>
 by: Bonita Montero - Tue, 19 Sep 2023 18:59 UTC

Am 19.09.2023 um 20:11 schrieb Paavo Helde:

> Nobody has denied there must be some synchronization in static
> initialization. Bonita would be right only if there is some
> possibility of failure when updating those flags.

If the mutexes for all static initializations would be pre-created
before main() I'd nothing to complain. The creation can fail, the
synchronization can fail according to the API, but is actually
very unlikely.

Re: Thread-safe initialization of static objects

<uecra6$2g3hn$1@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 12:03:33 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <uecra6$2g3hn$1@dont-email.me>
References: <udafjf$2joeq$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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<ueboet$29a2b$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 19:03:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2625079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZZ7+uEO0b4jfv8sdb5r696tg6hmPlzG4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:Ygy4h48BHY28wDyV+aAYHypdX4U=
Content-Language: en-US
In-Reply-To: <ueboet$29a2b$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 19:03 UTC

On 9/19/2023 2:08 AM, Chris M. Thomasson wrote:
> On 9/19/2023 1:46 AM, Bonita Montero wrote:
>> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>>
>>>> I've shown that static initialization actually uses a mutex per object.
>>
>>> Really?
>>
>> Here, a third time the code for you:
> [snip code]
>
> That does mean every impl must use a mutex per object wrt static
^^^^^^^^^^^^^^^^^^^^^

That does _not_ mean every

Damn typos!

> initialization. Just because you claim that they do, does not make it so.
>
>

Re: Thread-safe initialization of static objects

<uecrf8$2g3hn$2@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 12:06:16 -0700
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <uecrf8$2g3hn$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me> <ueboet$29a2b$1@dont-email.me>
<uebq3e$29k5u$1@dont-email.me> <mUfOM.25777$ZkX3.20078@fx09.iad>
<uec35s$2b8an$1@dont-email.me> <20230919073225.221@kylheku.com>
<uecn0t$2f5ud$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 19:06:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2625079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mhhGCyP5d+rpnt5WTsmcUp/oTraDws9I="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:bmAPI4mBWQ1AAyI3k5I/H8VVlfs=
Content-Language: en-US
In-Reply-To: <uecn0t$2f5ud$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 19:06 UTC

On 9/19/2023 10:50 AM, Bonita Montero wrote:
> Am 19.09.2023 um 18:41 schrieb Kaz Kylheku:
>
>> I don't suspect you can have a recursive initialization that isn't
>> erroneous.
>
> Recursive initialization of static object simply works if you have
> a mutex per object. I'm sure the standard requires that, otherwise
> you'd run into problems. Actually the three mentioned implementations
> support that because there's a mutex per objec.t
>
>> If an object is in progress of being initialized, I think
>> the program must prevent the re-entry of that.
>
> That's a further flag.
>
>> I'm surprised that you don't consider the possibility of
>> one mutex per "basic block":
>
> That's also a way to handle this, but I think the most elegant
> way would be to have a lock-free stack of mutexes as a pool and
> the mutex is given back to the pool by the last contender.
>
>> why couldn't we have a single hidden mutex serializing both
>> initializations, rather than two mutexes?
>
> That's transparent if the standard handles it this way or not.
>

An impl can also decide to use futexes, that do not need to create a
mutex per static initialization.

Re: Thread-safe initialization of static objects

<uecrgo$2g3hn$3@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 12:07:03 -0700
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <uecrgo$2g3hn$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad> <uecac1$2cj86$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 19 Sep 2023 19:07:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2625079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19alwI9MkjbD/PKAE2B7LGDe4WMtdszWV4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:u0GSeMK2IOTFuOyO8STCQ52WHoQ=
Content-Language: en-US
In-Reply-To: <uecac1$2cj86$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 19:07 UTC

On 9/19/2023 7:14 AM, Bonita Montero wrote:
> Am 19.09.2023 um 15:49 schrieb Scott Lurndal:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>>>
>>>>> I've shown that static initialization actually uses a mutex per
>>>>> object.
>>>
>>>> Really?
>>>
>>> Here, a third time the code for you:
>>
>> This code doesn't show any mutex at all.
>
> It is guaranteed that if multiple threads go through a line of code
> with static initialization, only one thread will actually initialize
> the static object and others will sleep meanwhile. This can't be
> handled without something that works like a mutex. It is irrelevant
> whether a std::mutex or a native mutex of the operating system is
> used. Others here have understood that this is the only way it works,
> the point of the discussion was simply whether exactly one mutex is
> responsible for all static initializations, which would make it
> possible to get through almost always without a malfunction, or
> whether it would be more static Initialization there is a  mutex.
> I have proven the latter with my code.
> So again: it is guaranteed that static initialization is thread-safe.
> The standard also says that if more than one thread wants to initialize
> statically, all others do not do so and ultimately sleep until the
> initialization is complete. Please tell me how this should work
> differently than with a mutex
>
>
>> Disassemble the code and find the synchronization object.
>
> Idiot.

Are you referring to yourself here? Just wondering.

Re: Thread-safe initialization of static objects

<uecrr6$2g3hn$4@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 12:12:37 -0700
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <uecrr6$2g3hn$4@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad>
<3ba58128-f2f5-4639-8b9d-606782c2b486n@googlegroups.com>
<ueco83$2fd1j$1@dont-email.me> <uecr23$2g167$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 19:12:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2625079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+byQ20osM8LCMcDrfoHpOj4ZKgInUrb+o="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:f+yOCbbS0juC9QfJ69SM3qzSeVU=
Content-Language: en-US
In-Reply-To: <uecr23$2g167$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 19:12 UTC

On 9/19/2023 11:59 AM, Bonita Montero wrote:
> Am 19.09.2023 um 20:11 schrieb Paavo Helde:
>
>> Nobody has denied there must be some synchronization in static
>> initialization. Bonita would be right only if there is some
>> possibility of failure when updating those flags.
>
> If the mutexes for all static initializations would be pre-created
> before main() I'd nothing to complain. The creation can fail, the
> synchronization can fail according to the API, but is actually
> very unlikely.
>

Futex has all the kernel resources created up front, Bonita. Also, there
was this interesting method I learned about many years ago:

<pseudo-code>
_______________________
static foo* g_foo = nullptr;

foo* l_foo = g_foo; // atomic load

if (! l_foo)
{ foo* t_foo = new foo;
foo* cmp = nullptr;

// CAS would update the comparand on failure.
// Take special note of that...

// mb release

if (! CAS(&g_foo, &cmp, t_foo)) // atomic rmw
{
// failed!!! well, shit happens!
delete t_foo;
t_foo = cmp;
// mb acquire
}

l_foo = t_foo;
}

else
{ // mb acquire
}

l_foo->bar();
_______________________

Its an interesting method to me.

Re: Thread-safe initialization of static objects

<uecs4n$2g3hn$5@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 12:17:43 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uecs4n$2g3hn$5@dont-email.me>
References: <udafjf$2joeq$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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<EjoNM.17221$DXgc.9861@fx36.iad> <ue5tfc$7pns$1@dont-email.me>
<zPGNM.14021$BMnd.11871@fx04.iad> <ue7f6g$frod$2@dont-email.me>
<ue7gdm$fumm$4@dont-email.me> <ue7hc3$g7tm$1@dont-email.me>
<ue7r4j$i3u1$1@dont-email.me> <ue8mid$q534$2@dont-email.me>
<O9XNM.16067$JX2f.12159@fx13.iad> <20230918110147.326@kylheku.com>
<uea42g$1sn0e$2@dont-email.me> <20230918123203.723@kylheku.com>
<ueb3q5$2638l$5@dont-email.me> <20230918205859.263@kylheku.com>
<uebn7l$293m3$3@dont-email.me> <20230919094617.529@kylheku.com>
<uecn60$2f5ud$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 19 Sep 2023 19:17:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2625079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/UvGWmMNoqrmZp5ac4tWJW+Th4prP16so="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:3bN9qguWR46AxlxIg70+mwMRWcE=
Content-Language: en-US
In-Reply-To: <uecn60$2f5ud$2@dont-email.me>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 19:17 UTC

On 9/19/2023 10:53 AM, Bonita Montero wrote:
> Am 19.09.2023 um 18:53 schrieb Kaz Kylheku:
>
>> That's what creates the posssibility of deadlock. You do understand
>> that if two threads stepwise try to lock the same pair of mutexes in
>> opposite order, you get deadlock?
>>
>>    Thread A                Thread B
>>       |                        |
>>    x.lock();                y.lock();
>>       |                        |
>>    y.lock()                 x.lock();
>>
>> A is waiting for B to release y, which is waiting for A to release x.
>
> Show me the code with static initialization that produces a deadlock.
> That would be possible with nested initialization, but when you nest
> you have always the same order, so this actually wouldn't give a
> deadlock.
>

A locking order is very important and must be enforced or deadlocks are
in your future... This is one reason why I sort the locks and remove
duplicates in my experimental multex:

https://groups.google.com/g/comp.lang.c++/c/sV4WC_cBb9Q/m/SkSqpSxGCAAJ

Re: Thread-safe initialization of static objects

<uecsse$2g3hn$7@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 12:30:21 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uecsse$2g3hn$7@dont-email.me>
References: <udafjf$2joeq$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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<ue7hb6$g6eb$1@dont-email.me> <ue7hdn$g7tm$2@dont-email.me>
<ue7hps$g6eb$4@dont-email.me> <ue7htp$g7tm$6@dont-email.me>
<ue7idv$gach$4@dont-email.me> <ue7j3g$ggh4$1@dont-email.me>
<ue7lnd$h1b4$1@dont-email.me> <ue8lpq$q25a$1@dont-email.me>
<uea7vf$1tgqs$1@dont-email.me> <ueb3c7$2638l$1@dont-email.me>
<ueb9up$271en$2@dont-email.me> <uebn0a$293m3$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 19 Sep 2023 19:30:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e823050642b27d6b26a63385ba2f7eca";
logging-data="2625079"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/MiXhnI3Q9crtpW3iq+7mKr8yg7SHl34I="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:ragnv9PmUytW590DvuMywUaI9QM=
Content-Language: en-US
In-Reply-To: <uebn0a$293m3$1@dont-email.me>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 19:30 UTC

On 9/19/2023 1:43 AM, Bonita Montero wrote:
> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>
>> We can choose to use the kernel to wait, if we choose to.
>> You are bringing back memories... Thanks for that Bonita. :^)
>
> The futex part of a mutex is for the slow path. It appears that
> this is done with a kernel intervention since there's no explicit
> kernel call.
>

A futex allows a programmer to use a predicate, akin to a condition
variable for lock/wait free algorithms. They are quite nice. Still, I
don't think you know how they actually work...

Re: Thread-safe initialization of static objects

<20230919140127.732@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-4973@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 21:08:03 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 83
Message-ID: <20230919140127.732@kylheku.com>
References: <udafjf$2joeq$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>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<EjoNM.17221$DXgc.9861@fx36.iad> <ue5tfc$7pns$1@dont-email.me>
<zPGNM.14021$BMnd.11871@fx04.iad> <ue7f6g$frod$2@dont-email.me>
<ue7gdm$fumm$4@dont-email.me> <ue7hc3$g7tm$1@dont-email.me>
<ue7r4j$i3u1$1@dont-email.me> <ue8mid$q534$2@dont-email.me>
<O9XNM.16067$JX2f.12159@fx13.iad> <20230918110147.326@kylheku.com>
<uea42g$1sn0e$2@dont-email.me> <20230918123203.723@kylheku.com>
<ueb3q5$2638l$5@dont-email.me> <20230918205859.263@kylheku.com>
<uebn7l$293m3$3@dont-email.me> <20230919094617.529@kylheku.com>
<uecn60$2f5ud$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 19 Sep 2023 21:08:03 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="78a1cbf526ee5626f6ff8689cdc8787c";
logging-data="2669378"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/VGMrTSm9LjoKN7SRMzinnnlSzaBcy1OQ="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:Fx03tnvNvxYWmLENRAFsCc44Ubo=
 by: Kaz Kylheku - Tue, 19 Sep 2023 21:08 UTC

On 2023-09-19, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 19.09.2023 um 18:53 schrieb Kaz Kylheku:
>
>> That's what creates the posssibility of deadlock. You do understand
>> that if two threads stepwise try to lock the same pair of mutexes in
>> opposite order, you get deadlock?
>>
>> Thread A Thread B
>> | |
>> x.lock(); y.lock();
>> | |
>> y.lock() x.lock();
>>
>> A is waiting for B to release y, which is waiting for A to release x.
>
> Show me the code with static initialization that produces a deadlock.

Uh, check your "Rest unread" folder?

Here is a complete sample. When I compile it with "g++ -pthread" on
Unbutu 18, the ./a.out hangs.

In gdb, it's obvious that it's hanging in some sort of lock acquiring
operation.

int B();
int A();

int A()
{ static int a = B();
return 'A';
}

int B()
{ static int b = A();
return 'B';
}

int main()
{ A();
return 0;
}

$ g++ -Wall -pthread staticinit.cc
staticinit.cc: In function ‘int A()’:
staticinit.cc:6:14: warning: unused variable ‘a’ [-Wunused-variable]
static int a = B();
^
staticinit.cc: In function ‘int B()’:
staticinit.cc:12:14: warning: unused variable ‘b’ [-Wunused-variable]
static int b = A();
^
$ ./a.out
^C
$ gdb ./a.out
GNU gdb (Ubuntu 8.1.1-0ubuntu1) 8.1.1
[ ... ]
Reading symbols from ./a.out...(no debugging symbols found)...done.
(gdb) r
Starting program: /home/kaz/junk/a.out
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/i386-linux-gnu/libthread_db.so.1".
^C
Program received signal SIGINT, Interrupt.
0xb7fd6d09 in __kernel_vsyscall ()
(gdb) bt
#0 0xb7fd6d09 in __kernel_vsyscall ()
#1 0xb7d07197 in syscall () at ../sysdeps/unix/sysv/linux/i386/syscall.S:29
#2 0xb7ea379d in __cxa_guard_acquire () from /usr/lib/i386-linux-gnu/libstdc++.so.6
#3 0x004006c2 in A() ()
#4 0x00400773 in B() ()
#5 0x004006d7 in A() ()
#6 0x004007e5 in main ()
(gdb)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Thread-safe initialization of static objects

<RtpOM.264$Sn81.213@fx08.iad>

  copy mid

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

  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!fx08.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$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> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me> <ueboet$29a2b$1@dont-email.me>
<uebq3e$29k5u$1@dont-email.me> <mUfOM.25777$ZkX3.20078@fx09.iad>
<uec35s$2b8an$1@dont-email.me>
From: Richard@Damon-Family.org (Richard Damon)
Content-Language: en-US
In-Reply-To: <uec35s$2b8an$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 21
Message-ID: <RtpOM.264$Sn81.213@fx08.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: Tue, 19 Sep 2023 18:42:57 -0400
X-Received-Bytes: 2447
 by: Richard Damon - Tue, 19 Sep 2023 22:42 UTC

On 9/19/23 8:11 AM, Bonita Montero wrote:
> Am 19.09.2023 um 13:48 schrieb Richard Damon:
>
>> IF there is a Mutex per individual object, where is it? Show the call
>> to make them.
>
> I've proven that because multiple static initializations of
> different objects run in parallel. Otherwise the code would
> have run 100 seconds.
> It makes sense to have a mutex per static object because with
> that you can also have recursive static inizialization, which
> would otherwise be not possible.
>

Nope, all that shows is the system can't JUST use one global Mutex.

Your logic also shows that you don't understand how it actually works.

"Makes Sense" doesn't mean "Is True".

Your logic is as bad as PO's

Re: Thread-safe initialization of static objects

<iwpOM.265$Sn81.181@fx08.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.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> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad> <uecac1$2cj86$1@dont-email.me>
From: Richard@Damon-Family.org (Richard Damon)
In-Reply-To: <uecac1$2cj86$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 41
Message-ID: <iwpOM.265$Sn81.181@fx08.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: Tue, 19 Sep 2023 18:45:33 -0400
X-Received-Bytes: 3058
 by: Richard Damon - Tue, 19 Sep 2023 22:45 UTC

On 9/19/23 10:14 AM, Bonita Montero wrote:
> Am 19.09.2023 um 15:49 schrieb Scott Lurndal:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>>>
>>>>> I've shown that static initialization actually uses a mutex per
>>>>> object.
>>>
>>>> Really?
>>>
>>> Here, a third time the code for you:
>>
>> This code doesn't show any mutex at all.
>
> It is guaranteed that if multiple threads go through a line of code
> with static initialization, only one thread will actually initialize
> the static object and others will sleep meanwhile. This can't be
> handled without something that works like a mutex. It is irrelevant
> whether a std::mutex or a native mutex of the operating system is
> used. Others here have understood that this is the only way it works,
> the point of the discussion was simply whether exactly one mutex is
> responsible for all static initializations, which would make it
> possible to get through almost always without a malfunction, or
> whether it would be more static Initialization there is a  mutex.
> I have proven the latter with my code.
> So again: it is guaranteed that static initialization is thread-safe.
> The standard also says that if more than one thread wants to initialize
> statically, all others do not do so and ultimately sleep until the
> initialization is complete. Please tell me how this should work
> differently than with a mutex
>
>
>> Disassemble the code and find the synchronization object.
>
> Idiot.

And there are things that work enough like a Mutex to do this, that
aren't Mutexes in the sense you are using, as they don't have the same
failure modes.

You are just showing how closed your mind is.

Re: Thread-safe initialization of static objects

<FxpOM.267$Sn81.209@fx08.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx08.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> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad>
<3ba58128-f2f5-4639-8b9d-606782c2b486n@googlegroups.com>
<ueco83$2fd1j$1@dont-email.me> <uecr23$2g167$1@dont-email.me>
From: Richard@Damon-Family.org (Richard Damon)
In-Reply-To: <uecr23$2g167$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 17
Message-ID: <FxpOM.267$Sn81.209@fx08.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: Tue, 19 Sep 2023 18:47:01 -0400
X-Received-Bytes: 2099
 by: Richard Damon - Tue, 19 Sep 2023 22:47 UTC

On 9/19/23 2:59 PM, Bonita Montero wrote:
> Am 19.09.2023 um 20:11 schrieb Paavo Helde:
>
>> Nobody has denied there must be some synchronization in static
>> initialization. Bonita would be right only if there is some
>> possibility of failure when updating those flags.
>
> If the mutexes for all static initializations would be pre-created
> before main() I'd nothing to complain. The creation can fail, the
> synchronization can fail according to the API, but is actually
> very unlikely.
>

So, you didn't read the explaination of how it was actually done.

I guess that shows your level of literacy.

Re: Thread-safe initialization of static objects

<ued8k6$2ihh0$1@dont-email.me>

  copy mid

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

  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.thomasson.1@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Tue, 19 Sep 2023 15:50:45 -0700
Organization: A noiseless patient Spider
Lines: 52
Message-ID: <ued8k6$2ihh0$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad> <uecac1$2cj86$1@dont-email.me>
<iwpOM.265$Sn81.181@fx08.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 19 Sep 2023 22:50:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="f6fa32ff36e5d8cee5f47474b078ec61";
logging-data="2704928"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18bfSmC0pzYGeHNBTPrI7s/hrL8kBLt0Gk="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:LToa0WS/dYNsIqBNguDLr81Abwk=
Content-Language: en-US
In-Reply-To: <iwpOM.265$Sn81.181@fx08.iad>
 by: Chris M. Thomasson - Tue, 19 Sep 2023 22:50 UTC

On 9/19/2023 3:45 PM, Richard Damon wrote:
> On 9/19/23 10:14 AM, Bonita Montero wrote:
>> Am 19.09.2023 um 15:49 schrieb Scott Lurndal:
>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>> Am 19.09.2023 um 07:01 schrieb Chris M. Thomasson:
>>>>
>>>>>> I've shown that static initialization actually uses a mutex per
>>>>>> object.
>>>>
>>>>> Really?
>>>>
>>>> Here, a third time the code for you:
>>>
>>> This code doesn't show any mutex at all.
>>
>> It is guaranteed that if multiple threads go through a line of code
>> with static initialization, only one thread will actually initialize
>> the static object and others will sleep meanwhile. This can't be
>> handled without something that works like a mutex. It is irrelevant
>> whether a std::mutex or a native mutex of the operating system is
>> used. Others here have understood that this is the only way it works,
>> the point of the discussion was simply whether exactly one mutex is
>> responsible for all static initializations, which would make it
>> possible to get through almost always without a malfunction, or
>> whether it would be more static Initialization there is a  mutex.
>> I have proven the latter with my code.
>> So again: it is guaranteed that static initialization is thread-safe.
>> The standard also says that if more than one thread wants to initialize
>> statically, all others do not do so and ultimately sleep until the
>> initialization is complete. Please tell me how this should work
>> differently than with a mutex
>>
>>
>>> Disassemble the code and find the synchronization object.
>>
>> Idiot.
>
> And there are things that work enough like a Mutex to do this, that
> aren't Mutexes in the sense you are using, as they don't have the same
> failure modes.
>
> You are just showing how closed your mind is.

An example of Bonita thinking along wrt everything must exactly adhere
to her certain way... Anything the disagrees with this must be an
idiotic moron?

https://youtu.be/WzSai5qtHr8

;^)


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

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor