Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

All laws are simulations of reality. -- John C. Lilly


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

<eE7PM.16350$3vM.3605@fx37.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!feeder1.feed.usenet.farm!feed.usenet.farm!peer01.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx37.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>
<iwpOM.265$Sn81.181@fx08.iad> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<ueggh5$3bq3f$1@dont-email.me> <uegsdo$3dj0r$1@dont-email.me>
<uei1g6$3l13h$2@dont-email.me> <ueiu42$3tima$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <ueiu42$3tima$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 20
Message-ID: <eE7PM.16350$3vM.3605@fx37.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: Thu, 21 Sep 2023 23:14:18 -0400
X-Received-Bytes: 2417
 by: Richard Damon - Fri, 22 Sep 2023 03:14 UTC

On 9/21/23 10:28 PM, Bonita Montero wrote:
> Am 21.09.2023 um 20:19 schrieb Chris M. Thomasson:
>
>> On 9/21/2023 12:47 AM, Bonita Montero wrote:
>
>>> We discussed yield with periodic polling.
>
>> An adaptive backoff ...
> Do you have ADHD ?
> We discussed yield with periodic polling.
>

Who said anything about "periodic" polling.

"Adaptive Backoff" is spin loop waiting for a short period of time
(length of time based on factors previously measured) after which it
decides to yield, and when that comes back, we try polling again.

Maybe you don't actually understand how any of this stuff works, because
people aren't using the "buzzwords" in the exact formula you think of them.

Re: Thread-safe initialization of static objects

<uej5q1$3uji0$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 06:39:30 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uej5q1$3uji0$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> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<ueggh5$3bq3f$1@dont-email.me> <uegsdo$3dj0r$1@dont-email.me>
<uei1g6$3l13h$2@dont-email.me> <ueiu42$3tima$1@dont-email.me>
<eE7PM.16350$3vM.3605@fx37.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 04:39:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="4148800"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+k+JgNAO1fuSPorvPnaJuWluOAI1J2Dog="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:/LJrhaX3Qz5FG6g9MEM27qfNXRI=
In-Reply-To: <eE7PM.16350$3vM.3605@fx37.iad>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Sep 2023 04:39 UTC

Am 22.09.2023 um 05:14 schrieb Richard Damon:

> Who said anything about "periodic" polling.

When you yield you have to do periodic polling since each yield-wakeup
doesn't guarante that you get the lock.

> "Adaptive Backoff" ...

I know what adaptive backoff is, but we weren't in this context
at this point.

Re: Thread-safe initialization of static objects

<uej5rh$3uji0$2@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 06:40:18 +0200
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <uej5rh$3uji0$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> <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> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me> <uegtd7$3dolc$1@dont-email.me>
<RW6PM.10144$hC28.451@fx01.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Sep 2023 04:40:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="4148800"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19R/xec+O/+yY8X3ne5YCXWqLCvk2DEy2g="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dWHdXeC+/YGqKizfcabd+Jldpfw=
Content-Language: de-DE
In-Reply-To: <RW6PM.10144$hC28.451@fx01.iad>
 by: Bonita Montero - Fri, 22 Sep 2023 04:40 UTC

Am 22.09.2023 um 04:25 schrieb Pavel:

> What are you trying to prove? ..

THat mem is initiallly zero, although this isn't guarenteed for
static fundamental types.

Re: Thread-safe initialization of static objects

<uej5tu$3uji0$3@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 06:41:35 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uej5tu$3uji0$3@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>
<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>
<aJINM.23275$H8td.10140@fx10.iad> <ue8lv5$q25a$3@dont-email.me>
<th7PM.6493$wGe2.6301@fx03.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 04:41:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="4148800"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Kb3jZBBHMn1vSTp633wWartgnAfbL2io="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Ws/912/hJ89yqwr55EotDzvuaQs=
In-Reply-To: <th7PM.6493$wGe2.6301@fx03.iad>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Sep 2023 04:41 UTC

Am 22.09.2023 um 04:50 schrieb Pavel:

> A "deferred" initialization of a static sync primitive used to sync
> static initialization of a C++ object is not only unnecessary (constant
> initialization is enough) but also would be useless if used. Because how
> would you correctly synchronize this "deferred" initialization itself if
> the initialization of the static object is requested concurrently from 2
> threads. You should stop invent and talk nonsense.

A lock may be never contended or contended very lately, so that
delayed allocation of the kernel semaphore may make sense.

Re: Thread-safe initialization of static objects

<uej631$3uji0$4@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 06:44:18 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <uej631$3uji0$4@dont-email.me>
References: <udafjf$2joeq$1@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>
<ZjMOM.9398$EIy4.4982@fx48.iad> <uegsia$3dj0r$2@dont-email.me>
<fp7PM.104556$GHI6.80009@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 04:44:17 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="4148800"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Yc36nHAZe4IzF+9CLwkg4fYjrIv+MSJY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:kQg5ANawPDQS7UoNWnWskU4q9OI=
In-Reply-To: <fp7PM.104556$GHI6.80009@fx17.iad>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Sep 2023 04:44 UTC

Am 22.09.2023 um 04:58 schrieb Pavel:

> It **is** the job of the standard authors to assume what elementary
> operations can and what cannot fail and build their specs upon that.

Mutex synchronization can fail at least in C++ because of delayed
initialization since the constructor itself of mutex is noexcept.
It's the same with whatever is used for static initializatiionsince
the mutex-ish data structure is created when there's contention.

Re: Thread-safe initialization of static objects

<20230921220955.181@kylheku.com>

  copy mid

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

  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-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 05:15:54 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <20230921220955.181@kylheku.com>
References: <udafjf$2joeq$1@dont-email.me> <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> <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> <aJINM.23275$H8td.10140@fx10.iad>
<ue8lv5$q25a$3@dont-email.me> <th7PM.6493$wGe2.6301@fx03.iad>
<uej5tu$3uji0$3@dont-email.me>
Injection-Date: Fri, 22 Sep 2023 05:15:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="56965"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/mIZFmHZ2ZDJjUG6jej0YAAhXErOqF5kY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:9Y7W8ePdVPWGwW5qnhKOPPCwYdw=
 by: Kaz Kylheku - Fri, 22 Sep 2023 05:15 UTC

On 2023-09-22, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 22.09.2023 um 04:50 schrieb Pavel:
>
>> A "deferred" initialization of a static sync primitive used to sync
>> static initialization of a C++ object is not only unnecessary (constant
>> initialization is enough) but also would be useless if used. Because how
>> would you correctly synchronize this "deferred" initialization itself if
>> the initialization of the static object is requested concurrently from 2
>> threads. You should stop invent and talk nonsense.
>
> A lock may be never contended or contended very lately, so that
> delayed allocation of the kernel semaphore may make sense.

Do you realize that if multiple threads race, they must somehow create a
single semaphore? One thread must create that semaphore and the others
use it?

And do you not see that that is itself an instance of the once-only
initialization problem? We have a semaphore handle, which must be
initialized once with a single semaphore object, which is used by
every thread that comes later?

If you've solved that problem, then can you explain why you wouldn't
get rid of the semaphore and just apply the solution directly to the
object you're actually trying to initialize?

--
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

<20230921222741.540@kylheku.com>

  copy mid

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

  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-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 05:34:06 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <20230921222741.540@kylheku.com>
References: <udafjf$2joeq$1@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> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me>
Injection-Date: Fri, 22 Sep 2023 05:34:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="61809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Ekc5GPpDQeHX2yyhN+L9BPEDEiJh6eOA="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:TgNBxXNDM47OtN8Ejo1E3SOOvmk=
 by: Kaz Kylheku - Fri, 22 Sep 2023 05:34 UTC

On 2023-09-22, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 22.09.2023 um 04:58 schrieb Pavel:
>
>> It **is** the job of the standard authors to assume what elementary
>> operations can and what cannot fail and build their specs upon that.
>
> Mutex synchronization can fail at least in C++ because of delayed
> initialization since the constructor itself of mutex is noexcept.

Based on what hypothesis? That objects with noexcept constructors
necessarily keep an exception bottled up inside, which goes off at some
later inopportune moment?

--
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

<uejdio$2g4g$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 08:52:10 +0200
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uejdio$2g4g$1@dont-email.me>
References: <udafjf$2joeq$1@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>
<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>
<aJINM.23275$H8td.10140@fx10.iad> <ue8lv5$q25a$3@dont-email.me>
<th7PM.6493$wGe2.6301@fx03.iad> <uej5tu$3uji0$3@dont-email.me>
<20230921220955.181@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 06:52:08 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="82064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7tOlt/G6Mvs8tX7NGbnt6zIxBNMxnHmI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:S3E+67ChU4OerADkji6zGwwCBBA=
In-Reply-To: <20230921220955.181@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Sep 2023 06:52 UTC

Am 22.09.2023 um 07:15 schrieb Kaz Kylheku:

> Do you realize that if multiple threads race, they must somehow create a
> single semaphore? One thread must create that semaphore and the others
> use it?

C++ enforces delayed creation by having a noexcept mutex constructor.
The only way to have delayed initialization with that is to specula-
tively create the semaphore on contention and and try to permanently
assign it to the mutex with a CAS. If the cas fails because another
contender has allocated the semaphore the semaphore is discarded,
i.e. given back to the kernel, and the semaphore already allocated
by another contender is used.
There's no way to handle that differently while a C++ mutex' is noecept.

Re: Thread-safe initialization of static objects

<uejdnb$2g4g$2@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 08:54:37 +0200
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <uejdnb$2g4g$2@dont-email.me>
References: <udafjf$2joeq$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>
<ZjMOM.9398$EIy4.4982@fx48.iad> <uegsia$3dj0r$2@dont-email.me>
<fp7PM.104556$GHI6.80009@fx17.iad> <uej631$3uji0$4@dont-email.me>
<20230921222741.540@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 06:54:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="82064"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3xyGJSEoXPABQGdhhEYr1y6viDZ11xeU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yw1234q1JT6Z0S3oP2in9ZLJGbA=
Content-Language: de-DE
In-Reply-To: <20230921222741.540@kylheku.com>
 by: Bonita Montero - Fri, 22 Sep 2023 06:54 UTC

Am 22.09.2023 um 07:34 schrieb Kaz Kylheku:

> On 2023-09-22, Bonita Montero <Bonita.Montero@gmail.com> wrote:

>> Mutex synchronization can fail at least in C++ because of delayed
>> initialization since the constructor itself of mutex is noexcept.

> Based on what hypothesis? That objects with noexcept constructors
> necessarily keep an exception bottled up inside, which goes off at
> some later inopportune moment?

As the mutex constructor is noexcept you can't allocate a kernel
semaphore within that because the allocation can fail. So the
allocation has to happen inside lock(), optimally at the first
time there's contention, since lock() allows to throw a system_error.

Re: Thread-safe initialization of static objects

<5e99eeff-e2dd-432b-ade5-3a20a553e140n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:620a:2092:b0:774:729:a9f4 with SMTP id e18-20020a05620a209200b007740729a9f4mr45830qka.2.1695377036945;
Fri, 22 Sep 2023 03:03:56 -0700 (PDT)
X-Received: by 2002:a05:687c:320f:b0:1d6:6040:7de with SMTP id
kz15-20020a05687c320f00b001d6604007demr3077877oac.9.1695377036584; Fri, 22
Sep 2023 03:03:56 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Fri, 22 Sep 2023 03:03:56 -0700 (PDT)
In-Reply-To: <20230921220955.181@kylheku.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2a0d:6fc2:55b0:ca00:f871:9f24:c014:651;
posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 2a0d:6fc2:55b0:ca00:f871:9f24:c014:651
References: <udafjf$2joeq$1@dont-email.me> <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> <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> <aJINM.23275$H8td.10140@fx10.iad>
<ue8lv5$q25a$3@dont-email.me> <th7PM.6493$wGe2.6301@fx03.iad>
<uej5tu$3uji0$3@dont-email.me> <20230921220955.181@kylheku.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <5e99eeff-e2dd-432b-ade5-3a20a553e140n@googlegroups.com>
Subject: Re: Thread-safe initialization of static objects
From: already5...@yahoo.com (Michael S)
Injection-Date: Fri, 22 Sep 2023 10:03:56 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 4772
 by: Michael S - Fri, 22 Sep 2023 10:03 UTC

On Friday, September 22, 2023 at 8:16:11 AM UTC+3, Kaz Kylheku wrote:
> On 2023-09-22, Bonita Montero <Bonita....@gmail.com> wrote:
> > Am 22.09.2023 um 04:50 schrieb Pavel:
> >
> >> A "deferred" initialization of a static sync primitive used to sync
> >> static initialization of a C++ object is not only unnecessary (constant
> >> initialization is enough) but also would be useless if used. Because how
> >> would you correctly synchronize this "deferred" initialization itself if
> >> the initialization of the static object is requested concurrently from 2
> >> threads. You should stop invent and talk nonsense.
> >
> > A lock may be never contended or contended very lately, so that
> > delayed allocation of the kernel semaphore may make sense.
> Do you realize that if multiple threads race, they must somehow create a
> single semaphore? One thread must create that semaphore and the others
> use it?
>
> And do you not see that that is itself an instance of the once-only
> initialization problem? We have a semaphore handle, which must be
> initialized once with a single semaphore object, which is used by
> every thread that comes later?
>
> If you've solved that problem, then can you explain why you wouldn't
> get rid of the semaphore and just apply the solution directly to the
> object you're actually trying to initialize?
> --

That's not the same.
The nature of initialization of local static object is unknown to C++
runtime support library. It can be short or long, compute intensive
or I/O intensive or even wait-intensive. The variability is what makes
the job challenging.
On the other hand, creation of kernel semaphore has well-known
characteristics - it is relatively short and compute-intensive.
With such characteristics, one does not need to invent complicated
schemes. A simplest solution will be adequate.
I.e. in the early stages of initialization you create a master mutex
with fully-initialized kernel mutex. Later on you use this master
mutex to serialize deferred part of initialization of other mutexes
and semaphores.

Pay attention, I didn't say that it's how it works in popular implementations.
Just say that it is possible and even somewhat sensible.

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

Re: Thread-safe initialization of static objects

<uejqlc$58ib$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 12:35:23 +0200
Organization: A noiseless patient Spider
Lines: 102
Message-ID: <uejqlc$58ib$1@dont-email.me>
References: <udafjf$2joeq$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> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me>
<5f5de245-c174-4f2d-9870-6a990123b524n@googlegroups.com>
<ueh0rk$3ebkg$1@dont-email.me>
<3af7b0b8-cfca-47d7-82cf-0d2bd3b8b321n@googlegroups.com>
<ueh8s7$3gh0c$1@dont-email.me>
<bed7f83a-18a0-4b4a-bb8c-cb8ff4a72ab4n@googlegroups.com>
<ueheuu$3hkm3$1@dont-email.me>
<bbde3ce4-b969-431e-a3f6-d0b5ec6aafacn@googlegroups.com>
<uei0u9$3l0uh$1@dont-email.me> <20230921112123.105@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 10:35:24 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb39865ea2ee1393c8c2cf4d99620574";
logging-data="172619"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Ge/P5PnlEFNmd1rjSwQWvI6ezVI1eTwI="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:5I5nh3+AJEJsMQgey0mdheFMjkE=
In-Reply-To: <20230921112123.105@kylheku.com>
Content-Language: en-GB
 by: David Brown - Fri, 22 Sep 2023 10:35 UTC

On 21/09/2023 20:39, Kaz Kylheku wrote:
> On 2023-09-21, David Brown <david.brown@hesbynett.no> wrote:
>> But I think for that kind of system, your recommended solution - don't
>> have function-local statics that need such initialisation
>> synchronisation - is far and away the most common solution.
>
> It could be as simple as putting the same variable outside of the
> function, so that the global construction takes care of it.
>

Yes, that is often the case. But there can be complications if this
requires dynamic code. There is the well-known matter of initialisation
/ construction order for statically allocated objects in C++. In
embedded systems, there is another matter - the system may not be ready
to handle the object's initialisation code until some of main()'s code
has run (such as for setting up hardware like external memory, clocks,
etc.).

The typical practice is to put the static objects outside of any
functions, and to use initialisation methods (or stand-alone functions)
rather than constructors. This works well enough, but you lose the
strong guarantees of object consistency that you get with constructors
(unless you have a "initialised" flag in each object, and check it for
each method - a not insignificant overhead).

> I don't think that global construction/initialization in C++ is a very
> good feature. You often need to maintain a strict order among
> global initializations. The order of global constructions is basically
> left to chance. It might follow the order in which the object files
> were linked or whatever.

You can improve things with compiler extensions, such as gcc's
"init_priority" attribute. Perhaps that could be standardised in some
way. Together with inline variables, this would, I think, eliminate
most cases of "singleton" patterns or the need to use lazy or delayed
construction to enforce particular orderings.

To be honest, I have difficulty thinking of many situations where you
would need a statically allocated object that is not constructed until
first use, let alone needing thread-safe construction. I think it would
have been better if C++ had effectively hoisted static locals to
file-scope level for constructor/destructor purposes, while retaining
scope and access restrictions - just like in C. Let those few
situations where you actually need initialisation control use an "init"
method, with whatever locking or synchronisation you deem appropriate.

>
> Only initializations that have absolutely no dependencies can be
> confidently put into the global scope.
>
> A possible reason why some programmers put complex static
> initializations into a block scope is to delay that initialization,
> since it will happen at a time when all the global ones have done.
>
> In my experience, global initialization can sometimes grow complex and
> need to be broken into phases: early initialization, late
> initialization. Possibly more than two.
>
> Block scope static initialization could be serving as an /ad hoc/
> late initialization.
>
> --
>
> I wonder whether anyone has ever experimented with a way of controlling
> the order of global C++ initializations by manipulating link order.
>

Using link order for that sounds extremely fragile. You can rely on the
order of definitions within a single translation unit (though inline
variables may make a mess of that if you are inconsistent). And if you
use compiler extensions (like gcc's "init_priority" attribute), you can
rely on them. But using link order sounds risky to me unless you have
specific toolchain-documented ways to handle this.

> Say that in a given implementation we can rely on the fact that if
> object files a.o b.o c.o are linked in that order, then their global
> constructions are done in that order.
>

If you are working with a manual linker file, and a specific toolchain
with a specific version, you can certainly do that kind of thing. In my
embedded (not embedded Linux) projects, the toolchain is always fixed at
a particular version (almost always a gcc toolchain), and I have the
linker file for it. I can see how the global constructors are called,
and make sure they are linked and run in exactly the order I want. But
in other types of programming, you don't have that kind of control -
only a tiny fraction of C++ programmers are even aware of "linker files"
or how you could control linking, and most don't have that kind of
control of the toolchains used for their code even if they know how to
do it.

> We could then deduce the dependencies among them (say, from
> header file inclusions: if b.cc includes "a.h", but a.cc does not
> include "b.h", we can infer that b depends on a). Then topologically
> sort the .o files accordingly.
>

This all needs a "whole program" overview, which would be a huge step
for C++.

Re: Thread-safe initialization of static objects

<uejse7$5ut5$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 13:05:42 +0200
Organization: A noiseless patient Spider
Lines: 27
Message-ID: <uejse7$5ut5$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <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>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<5f5de245-c174-4f2d-9870-6a990123b524n@googlegroups.com>
<ueh0rk$3ebkg$1@dont-email.me>
<3af7b0b8-cfca-47d7-82cf-0d2bd3b8b321n@googlegroups.com>
<ueh8s7$3gh0c$1@dont-email.me>
<bed7f83a-18a0-4b4a-bb8c-cb8ff4a72ab4n@googlegroups.com>
<ueheuu$3hkm3$1@dont-email.me>
<bbde3ce4-b969-431e-a3f6-d0b5ec6aafacn@googlegroups.com>
<uei0u9$3l0uh$1@dont-email.me>
<168b8330-93d1-43ca-a886-01a9bec8b2den@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Sep 2023 11:05:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb39865ea2ee1393c8c2cf4d99620574";
logging-data="195493"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1868YGWAizetCxuH+RJ+hanNRw97QMe9aQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:1cnf3KY+ejGbWyM99xxuD5thHxo=
Content-Language: en-GB
In-Reply-To: <168b8330-93d1-43ca-a886-01a9bec8b2den@googlegroups.com>
 by: David Brown - Fri, 22 Sep 2023 11:05 UTC

On 21/09/2023 23:44, Michael S wrote:
> On Thursday, September 21, 2023 at 9:10:36 PM UTC+3, David Brown wrote:
>>
>> Looking at generated code (using godbolt.org) for Linux, it seems there
>> is just a single byte boolean guard per object - there is no thread id
>> or anything else stored per object. I don't know what is going on
>> inside "__cxa_guard_acquire" and other such functions, however.
>
> That's not what I see on x86-64.
> I see size of guard object = 8 bytes. Both Windows and Linux, both
> gcc and clang.
>

<https://godbolt.org/z/WTax3T13s>

It is entirely possible that the guard gets more space, for alignment
purposes. But it is easy to see from the generated assembly here that
only a single byte is read and tested for the guard. When compiling
with 32-bit ARM gcc, a 32-bit word is read, but it is left-shifted by 31
bits before testing. That means all but the LSB is ignored.

The storage to the guard object (when "-fno-threadsafe-statics" is not
in operation) is done by the "__cxa_guard_release" function, so I don't
know what that actually stores - all you can see from the assembly here
is what is read.

Re: Thread-safe initialization of static objects

<0VePM.25326$fUu6.8952@fx47.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.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> <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>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<uegtd7$3dolc$1@dont-email.me> <RW6PM.10144$hC28.451@fx01.iad>
<uej5rh$3uji0$2@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
Content-Language: en-US
In-Reply-To: <uej5rh$3uji0$2@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 15
Message-ID: <0VePM.25326$fUu6.8952@fx47.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: Fri, 22 Sep 2023 07:30:03 -0400
X-Received-Bytes: 2242
 by: Richard Damon - Fri, 22 Sep 2023 11:30 UTC

On 9/22/23 12:40 AM, Bonita Montero wrote:
> Am 22.09.2023 um 04:25 schrieb Pavel:
>
>> What are you trying to prove? ..
>
> THat mem is initiallly zero, although this isn't guarenteed for
> static fundamental types.
>

Except that it is.

It isn't guaranteed for "auto" variables, but is for static variables,
those are ALWAYS zero-initialized at the start of program.

Maybe you should actually read the Standard.

Re: Thread-safe initialization of static objects

<gWePM.25327$fUu6.21270@fx47.iad>

  copy mid

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

  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!fx47.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>
<iwpOM.265$Sn81.181@fx08.iad> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<ueggh5$3bq3f$1@dont-email.me> <uegsdo$3dj0r$1@dont-email.me>
<uei1g6$3l13h$2@dont-email.me> <ueiu42$3tima$1@dont-email.me>
<eE7PM.16350$3vM.3605@fx37.iad> <uej5q1$3uji0$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <uej5q1$3uji0$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 19
Message-ID: <gWePM.25327$fUu6.21270@fx47.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: Fri, 22 Sep 2023 07:31:24 -0400
X-Received-Bytes: 2241
 by: Richard Damon - Fri, 22 Sep 2023 11:31 UTC

On 9/22/23 12:39 AM, Bonita Montero wrote:
> Am 22.09.2023 um 05:14 schrieb Richard Damon:
>
>> Who said anything about "periodic" polling.
>
> When you yield you have to do periodic polling since each yield-wakeup
> doesn't guarante that you get the lock.
>
>> "Adaptive Backoff" ...
>
> I know what adaptive backoff is, but we weren't in this context
> at this point.
>
>

Maybe YOU aren't, but "Adaptive Backoff" is one way to implement what I
was talking about.

Just shows that you don't actually know what we are talking about.

Re: Thread-safe initialization of static objects

<a4fa38b2-7fb6-477f-add6-48e5ddb8f23an@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:6214:162e:b0:656:22c3:cf23 with SMTP id e14-20020a056214162e00b0065622c3cf23mr87769qvw.11.1695383434181;
Fri, 22 Sep 2023 04:50:34 -0700 (PDT)
X-Received: by 2002:a05:6830:1cc:b0:6bc:fb26:499e with SMTP id
r12-20020a05683001cc00b006bcfb26499emr2671904ota.2.1695383433867; Fri, 22 Sep
2023 04:50:33 -0700 (PDT)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!border-2.nntp.ord.giganews.com!border-1.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Fri, 22 Sep 2023 04:50:33 -0700 (PDT)
In-Reply-To: <uejse7$5ut5$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=87.68.182.115; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 87.68.182.115
References: <udafjf$2joeq$1@dont-email.me> <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>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<5f5de245-c174-4f2d-9870-6a990123b524n@googlegroups.com> <ueh0rk$3ebkg$1@dont-email.me>
<3af7b0b8-cfca-47d7-82cf-0d2bd3b8b321n@googlegroups.com> <ueh8s7$3gh0c$1@dont-email.me>
<bed7f83a-18a0-4b4a-bb8c-cb8ff4a72ab4n@googlegroups.com> <ueheuu$3hkm3$1@dont-email.me>
<bbde3ce4-b969-431e-a3f6-d0b5ec6aafacn@googlegroups.com> <uei0u9$3l0uh$1@dont-email.me>
<168b8330-93d1-43ca-a886-01a9bec8b2den@googlegroups.com> <uejse7$5ut5$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a4fa38b2-7fb6-477f-add6-48e5ddb8f23an@googlegroups.com>
Subject: Re: Thread-safe initialization of static objects
From: already5...@yahoo.com (Michael S)
Injection-Date: Fri, 22 Sep 2023 11:50:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 52
 by: Michael S - Fri, 22 Sep 2023 11:50 UTC

On Friday, September 22, 2023 at 2:06:05 PM UTC+3, David Brown wrote:
> On 21/09/2023 23:44, Michael S wrote:
> > On Thursday, September 21, 2023 at 9:10:36 PM UTC+3, David Brown wrote:
> >>
> >> Looking at generated code (using godbolt.org) for Linux, it seems there
> >> is just a single byte boolean guard per object - there is no thread id
> >> or anything else stored per object. I don't know what is going on
> >> inside "__cxa_guard_acquire" and other such functions, however.
> >
> > That's not what I see on x86-64.
> > I see size of guard object = 8 bytes. Both Windows and Linux, both
> > gcc and clang.
> >
> <https://godbolt.org/z/WTax3T13s>
>
> It is entirely possible that the guard gets more space, for alignment
> purposes.

It's not "possible", it's fact. You can see it on godbolt with right setting
of presentation flags.
.comm _ZGVZ3foovE1a,8,8
https://godbolt.org/z/bhx3dar17
I don't believe that it has anything to do with alignment. Byte variables
do not need alignment, even for atomicity.

> But it is easy to see from the generated assembly here that
> only a single byte is read and tested for the guard.

It's easy to see that compiled code uses only first byte.
It's not easy to see how the storage used by __cxa_guard_xxx
support routines.

> When compiling
> with 32-bit ARM gcc, a 32-bit word is read, but it is left-shifted by 31
> bits before testing. That means all but the LSB is ignored.
>

On 32-bit ARM the size=4
On 64-bit ARM the size=8
On 32-bit x86 the size=8

> The storage to the guard object (when "-fno-threadsafe-statics" is not
> in operation) is done by the "__cxa_guard_release" function, so I don't
> know what that actually stores - all you can see from the assembly here
> is what is read.

Re: Thread-safe initialization of static objects

<907276cd-6415-404d-8244-168cea08798en@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
X-Received: by 2002:a05:6214:b90:b0:649:fc3d:7659 with SMTP id fe16-20020a0562140b9000b00649fc3d7659mr96372qvb.12.1695383910638;
Fri, 22 Sep 2023 04:58:30 -0700 (PDT)
X-Received: by 2002:a05:6808:208a:b0:39c:a74b:81d6 with SMTP id
s10-20020a056808208a00b0039ca74b81d6mr4384220oiw.7.1695383910502; Fri, 22 Sep
2023 04:58:30 -0700 (PDT)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c++
Date: Fri, 22 Sep 2023 04:58:30 -0700 (PDT)
In-Reply-To: <0VePM.25326$fUu6.8952@fx47.iad>
Injection-Info: google-groups.googlegroups.com; posting-host=87.68.182.115; posting-account=ow8VOgoAAAAfiGNvoH__Y4ADRwQF1hZW
NNTP-Posting-Host: 87.68.182.115
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>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<uegtd7$3dolc$1@dont-email.me> <RW6PM.10144$hC28.451@fx01.iad>
<uej5rh$3uji0$2@dont-email.me> <0VePM.25326$fUu6.8952@fx47.iad>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <907276cd-6415-404d-8244-168cea08798en@googlegroups.com>
Subject: Re: Thread-safe initialization of static objects
From: already5...@yahoo.com (Michael S)
Injection-Date: Fri, 22 Sep 2023 11:58:30 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3002
 by: Michael S - Fri, 22 Sep 2023 11:58 UTC

On Friday, September 22, 2023 at 2:30:22 PM UTC+3, Richard Damon wrote:
> On 9/22/23 12:40 AM, Bonita Montero wrote:
> > Am 22.09.2023 um 04:25 schrieb Pavel:
> >
> >> What are you trying to prove? ..
> >
> > THat mem is initiallly zero, although this isn't guarenteed for
> > static fundamental types.
> >
> Except that it is.
>
> It isn't guaranteed for "auto" variables, but is for static variables,
> those are ALWAYS zero-initialized at the start of program.
>
> Maybe you should actually read the Standard.

TI tools for C5000 family were known to ignore this part of the Standard.
At least for C. I newer used TI C++ compilers.
In early 2000s they had a special flag that forced a standard
behavior. I am not sure that such flag existed in 90s and for earlier
families, esp. for C20/C25.

Re: Thread-safe initialization of static objects

<uek0g4$7fl1$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 14:15:02 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uek0g4$7fl1$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> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<ueggh5$3bq3f$1@dont-email.me> <uegsdo$3dj0r$1@dont-email.me>
<uei1g6$3l13h$2@dont-email.me> <ueiu42$3tima$1@dont-email.me>
<eE7PM.16350$3vM.3605@fx37.iad> <uej5q1$3uji0$1@dont-email.me>
<gWePM.25327$fUu6.21270@fx47.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 12:15:00 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="245409"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/09qXaTUqmTqS6mYhKTo6AHn+MGiv5kkg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:tiVe+fwJ+J/txCr4QkwgpjrM8+g=
Content-Language: de-DE
In-Reply-To: <gWePM.25327$fUu6.21270@fx47.iad>
 by: Bonita Montero - Fri, 22 Sep 2023 12:15 UTC

Am 22.09.2023 um 13:31 schrieb Richard Damon:

> Just shows that you don't actually know what we are talking about.

We're talking about if everything different like a mutex is acceptable
here. And it isn't. Yielding might have a too high delay under load
and spinning is dangerous in userspace because of what I've said.

Re: Thread-safe initialization of static objects

<uek88r$9itd$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 16:27:39 +0200
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <uek88r$9itd$1@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> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me> <uegtd7$3dolc$1@dont-email.me>
<RW6PM.10144$hC28.451@fx01.iad> <uej5rh$3uji0$2@dont-email.me>
<0VePM.25326$fUu6.8952@fx47.iad>
<907276cd-6415-404d-8244-168cea08798en@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Sep 2023 14:27:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb39865ea2ee1393c8c2cf4d99620574";
logging-data="314285"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18rnhCpTUCTkXne7xxFyBoIoqCkBtGCW/E="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Tm8BZqv3tS9rCyzfvjIX3D8ZOGg=
In-Reply-To: <907276cd-6415-404d-8244-168cea08798en@googlegroups.com>
Content-Language: en-GB
 by: David Brown - Fri, 22 Sep 2023 14:27 UTC

On 22/09/2023 13:58, Michael S wrote:
> On Friday, September 22, 2023 at 2:30:22 PM UTC+3, Richard Damon wrote:
>> On 9/22/23 12:40 AM, Bonita Montero wrote:
>>> Am 22.09.2023 um 04:25 schrieb Pavel:
>>>
>>>> What are you trying to prove? ..
>>>
>>> THat mem is initiallly zero, although this isn't guarenteed for
>>> static fundamental types.
>>>
>> Except that it is.
>>
>> It isn't guaranteed for "auto" variables, but is for static variables,
>> those are ALWAYS zero-initialized at the start of program.
>>
>> Maybe you should actually read the Standard.
>
> TI tools for C5000 family were known to ignore this part of the Standard.
> At least for C. I newer used TI C++ compilers.
> In early 2000s they had a special flag that forced a standard
> behavior. I am not sure that such flag existed in 90s and for earlier
> families, esp. for C20/C25.
>

There's a reason TI's tools were known as "Code Composter", rather than
"Code Composer" as it said on the box...

I don't know of any other tools (C or C++) than TI's that did not zero
out uninitialised data at startup, but TI's were famous for it. It
caused a lot of "fun" for developers who could not figure out why their
code sometimes worked and sometimes failed (depending on the old
contents of the ram), and a lot of unnecessarily inefficient portable
code that explicitly initialised static data with zeros in case someone
used TI's tools.

Re: Thread-safe initialization of static objects

<ueka81$9v9t$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 17:01:20 +0200
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <ueka81$9v9t$1@dont-email.me>
References: <udafjf$2joeq$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> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me>
<5f5de245-c174-4f2d-9870-6a990123b524n@googlegroups.com>
<ueh0rk$3ebkg$1@dont-email.me>
<3af7b0b8-cfca-47d7-82cf-0d2bd3b8b321n@googlegroups.com>
<ueh8s7$3gh0c$1@dont-email.me>
<bed7f83a-18a0-4b4a-bb8c-cb8ff4a72ab4n@googlegroups.com>
<ueheuu$3hkm3$1@dont-email.me>
<bbde3ce4-b969-431e-a3f6-d0b5ec6aafacn@googlegroups.com>
<uei0u9$3l0uh$1@dont-email.me>
<168b8330-93d1-43ca-a886-01a9bec8b2den@googlegroups.com>
<uejse7$5ut5$1@dont-email.me>
<a4fa38b2-7fb6-477f-add6-48e5ddb8f23an@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Sep 2023 15:01:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="bb39865ea2ee1393c8c2cf4d99620574";
logging-data="326973"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+HDCI/w3bBloLWEhWgINPy7QtT3oAC+as="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:m123w0PVZJ8TDwpLbodNesDyoo0=
Content-Language: en-GB
In-Reply-To: <a4fa38b2-7fb6-477f-add6-48e5ddb8f23an@googlegroups.com>
 by: David Brown - Fri, 22 Sep 2023 15:01 UTC

On 22/09/2023 13:50, Michael S wrote:
> On Friday, September 22, 2023 at 2:06:05 PM UTC+3, David Brown wrote:
>> On 21/09/2023 23:44, Michael S wrote:
>>> On Thursday, September 21, 2023 at 9:10:36 PM UTC+3, David Brown wrote:
>>>>
>>>> Looking at generated code (using godbolt.org) for Linux, it seems there
>>>> is just a single byte boolean guard per object - there is no thread id
>>>> or anything else stored per object. I don't know what is going on
>>>> inside "__cxa_guard_acquire" and other such functions, however.
>>>
>>> That's not what I see on x86-64.
>>> I see size of guard object = 8 bytes. Both Windows and Linux, both
>>> gcc and clang.
>>>
>> <https://godbolt.org/z/WTax3T13s>
>>
>> It is entirely possible that the guard gets more space, for alignment
>> purposes.
>
> It's not "possible", it's fact. You can see it on godbolt with right setting
> of presentation flags.
> .comm _ZGVZ3foovE1a,8,8
> https://godbolt.org/z/bhx3dar17
> I don't believe that it has anything to do with alignment. Byte variables
> do not need alignment, even for atomicity.
>
>> But it is easy to see from the generated assembly here that
>> only a single byte is read and tested for the guard.
>
> It's easy to see that compiled code uses only first byte.
> It's not easy to see how the storage used by __cxa_guard_xxx
> support routines.

Perhaps the larger guard variable size is used between the
__cxa_guard_acquire, and the cxa_guard_release calls? In the end, I am
quite confident that the guard variable gets a 1 written to it, but it
could get some kind of thread information written during the actual
construction.

>
>> When compiling
>> with 32-bit ARM gcc, a 32-bit word is read, but it is left-shifted by 31
>> bits before testing. That means all but the LSB is ignored.
>>
>
> On 32-bit ARM the size=4
> On 64-bit ARM the size=8
> On 32-bit x86 the size=8
>
>> The storage to the guard object (when "-fno-threadsafe-statics" is not
>> in operation) is done by the "__cxa_guard_release" function, so I don't
>> know what that actually stores - all you can see from the assembly here
>> is what is read.

Re: Thread-safe initialization of static objects

<uekiup$bci8$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 10:30:00 -0700
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <uekiup$bci8$1@dont-email.me>
References: <udafjf$2joeq$1@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> <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> <aJINM.23275$H8td.10140@fx10.iad>
<ue8lv5$q25a$3@dont-email.me> <th7PM.6493$wGe2.6301@fx03.iad>
<uej5tu$3uji0$3@dont-email.me> <20230921220955.181@kylheku.com>
<uejdio$2g4g$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 17:30:01 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="853f841f6b4e635c8356e4e350d42a4d";
logging-data="373320"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Ko3JrN7x9gSLSYBRKaEjIEc9oPPnYryw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:SSwbw5TXMz6hwrOAtokiT9wuNas=
In-Reply-To: <uejdio$2g4g$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 22 Sep 2023 17:30 UTC

On 9/21/2023 11:52 PM, Bonita Montero wrote:
> Am 22.09.2023 um 07:15 schrieb Kaz Kylheku:
>
>> Do you realize that if multiple threads race, they must somehow create a
>> single semaphore? One thread must create that semaphore and the others
>> use it?
>
> C++ enforces delayed creation by having a noexcept mutex constructor.
> The only way to have delayed initialization with that is to specula-
> tively create the semaphore on contention and and try to permanently
> assign it to the mutex with a CAS. If the cas fails because another
> contender has allocated the semaphore the semaphore is discarded,
> i.e. given back to the kernel, and the semaphore already allocated
> by another contender is used.

Fwiw, that's exactly how this works, I posted about it elsewhere in this
thread:
______________________
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
}

// I forgot to do this in my prior pseudo code.
// ARGH!!! ;^o

l_foo = t_foo; // damn it, sorry again.
}

else
{ // mb acquire
}

l_foo->bar();
______________________

> There's no way to handle that differently while a C++ mutex' is noecept.

Why do you say that!? A futex does not make the user code create any
kernel resources. You are a fairly stubborn person! :^)

Re: Thread-safe initialization of static objects

<uekj9c$bfh8$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 19:35:41 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <uekj9c$bfh8$1@dont-email.me>
References: <udafjf$2joeq$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>
<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>
<aJINM.23275$H8td.10140@fx10.iad> <ue8lv5$q25a$3@dont-email.me>
<th7PM.6493$wGe2.6301@fx03.iad> <uej5tu$3uji0$3@dont-email.me>
<20230921220955.181@kylheku.com> <uejdio$2g4g$1@dont-email.me>
<uekiup$bci8$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 17:35:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="376360"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/4xR8Jx9TGGPcjehvrqbphAJvMpKceLEA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:qjG1Me7NfHPotwpnyqQ/8/JDqf0=
Content-Language: de-DE
In-Reply-To: <uekiup$bci8$1@dont-email.me>
 by: Bonita Montero - Fri, 22 Sep 2023 17:35 UTC

Am 22.09.2023 um 19:30 schrieb Chris M. Thomasson:

> Why do you say that!? A futex does not make the user code create any
> kernel resources. You are a fairly stubborn person! :^)

A futex is a replacement for the slow path, replacing a binary
semaphore. It requires to make the futexes's address to be read
-only to trap accesses and it requires a waiter's queue inside
the kernel.
Your misconception is that you think the futex is pure userspace,
but the difference is just that there's no explicit kernel-call
but a MMU-trap, which is faster on most CPUs than a explicit
kernel-call. So a futex is not possible without a MMU, documented
here: https://bugzilla.kernel.org/show_bug.cgi?id=78881

Re: Thread-safe initialization of static objects

<uekjd4$bci8$2@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 10:37:39 -0700
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <uekjd4$bci8$2@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>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<5f5de245-c174-4f2d-9870-6a990123b524n@googlegroups.com>
<ueh0rk$3ebkg$1@dont-email.me> <uei2ji$3l87c$2@dont-email.me>
<ueiu87$3tima$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Sep 2023 17:37:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="853f841f6b4e635c8356e4e350d42a4d";
logging-data="373320"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Gmw18ZM6CNTiPfMeeFB5epFRgBxB+Yt0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:moweVTaWm2rCXy4WlGguwNSQnwo=
In-Reply-To: <ueiu87$3tima$4@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 22 Sep 2023 17:37 UTC

On 9/21/2023 7:30 PM, Bonita Montero wrote:
> Am 21.09.2023 um 20:38 schrieb Chris M. Thomasson:
>> On 9/21/2023 2:02 AM, Bonita Montero wrote:
>>> Am 21.09.2023 um 10:38 schrieb Michael S:
>>>
>>>> Actually, considering that contention is very rare in practice, ...
>>>
>>> The initialization might last an arbitrary time, so spinning
>>> is inacceptable.
>>>
>>>> So even use of Futex | Critical Section | SRW lock,  although it make
>>>> a lot of sense in practice,  is not necessary from theoretical P.O.V.
>>>
>>> Why should a SRW-lock make sense here ? If the object isn't initialized
>>> iz can't be read meanwhile. And a futex isn't a replacement for a mutex
>>> but just a faster slow path for a mutex.

A faster slow path? A slow path using a futex or a semaphore are "slow"
by default. They go into the kernel. Afaict, you have very limited
experience with them. Fwiw, here is a pretty nice rwmutex that has no
loops in its logic:

https://vorbrodt.blog/2019/02/14/read-write-mutex

I created this many moons ago. It was fun to design. No loops can be a
pretty tall order! ;^)

>> A futex can be used to build a mutex, semaphore, a condition variable,
>> ect... A futex is a nice building block that works out pretty damn good.
>
> We were disussing SRW-locks, how they're implemented doesn't matter here.

Huh? Were are discussing static initialization and how a futex can be
used to handle it. Take note of the name of the thread itself. A rwmutex
can be implemented with a futex for the slow paths, no problem.

>> Have a lock-free algorithm that you want to make block on certain
>> conditions, build a predicate and we can use it with a futex.

Re: Thread-safe initialization of static objects

<uekjfq$bci8$3@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 10:39:05 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uekjfq$bci8$3@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> <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> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me> <DS6PM.104552$GHI6.65122@fx17.iad>
<ueiuar$3tima$5@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 17:39:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="853f841f6b4e635c8356e4e350d42a4d";
logging-data="373320"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19K5QQQnBJc3x0YVxkbPoAjXNZ/v5rNyC8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:3BBTk14Ufdxbq7udFOI0tXCFV7s=
In-Reply-To: <ueiuar$3tima$5@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 22 Sep 2023 17:39 UTC

On 9/21/2023 7:31 PM, Bonita Montero wrote:
> Am 22.09.2023 um 04:21 schrieb Pavel:
>
>> How does the above prove your wrong point that initialization of
>> static synchronization primitives always may fail? ...
>
> The mutex is created along with the static object from zeroed memory
> whene there's contention. At least this may fail. And with Windows
> the synchronization may also fail.
>
>

Sometimes you make blood want to shoot out of my eyes when I read what
you wrote.

Re: Thread-safe initialization of static objects

<uekjkd$bci8$4@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 10:41:32 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <uekjkd$bci8$4@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> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me> <uegtd7$3dolc$1@dont-email.me>
<RW6PM.10144$hC28.451@fx01.iad> <uej5rh$3uji0$2@dont-email.me>
<0VePM.25326$fUu6.8952@fx47.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 22 Sep 2023 17:41:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="853f841f6b4e635c8356e4e350d42a4d";
logging-data="373320"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18NGvZSARhyAXBLim23CWw4AsLFUeKIUrQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:doWyrvdWcWzcrOrQTdOJ7Sxf87s=
Content-Language: en-US
In-Reply-To: <0VePM.25326$fUu6.8952@fx47.iad>
 by: Chris M. Thomasson - Fri, 22 Sep 2023 17:41 UTC

On 9/22/2023 4:30 AM, Richard Damon wrote:
> On 9/22/23 12:40 AM, Bonita Montero wrote:
>> Am 22.09.2023 um 04:25 schrieb Pavel:
>>
>>> What are you trying to prove? ..
>>
>> THat mem is initiallly zero, although this isn't guarenteed for
>> static fundamental types.
>>
>
> Except that it is.
>
> It isn't guaranteed for "auto" variables, but is for static variables,
> those are ALWAYS zero-initialized at the start of program.
>
> Maybe you should actually read the Standard.

Afaict, Bonita needs to study up on a great many things when it comes to
synchronization. Sometimes, I think Bonita is actually trolling on
purpose... Humm...

Re: Thread-safe initialization of static objects

<uekk4v$bl34$1@dont-email.me>

  copy mid

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

  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: Fri, 22 Sep 2023 19:50:24 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uekk4v$bl34$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>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<uegtd7$3dolc$1@dont-email.me> <RW6PM.10144$hC28.451@fx01.iad>
<uej5rh$3uji0$2@dont-email.me> <0VePM.25326$fUu6.8952@fx47.iad>
<uekjkd$bci8$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 17:50:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="382052"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3i2SDmxRGD57BrMD2nZuJOnHIUaC+RUI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:XVCId6FDZwTPy+PMts3lcnd8deo=
In-Reply-To: <uekjkd$bci8$4@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Sep 2023 17:50 UTC

Am 22.09.2023 um 19:41 schrieb Chris M. Thomasson:

> Afaict, Bonita needs to study up on a great many things when it comes
> to synchronization. Sometimes, I think Bonita is actually trolling on
> purpose... Humm...

The problem is not that I don't understand synchronization, the problem
is that I don't accept your objections where they don't fit the context.


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

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor