Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

"From there to here, from here to there, funny things are everywhere." -- Dr. Seuss


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

<20230918103046.498@kylheku.com>

  copy mid

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

  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: Mon, 18 Sep 2023 17:34:37 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 34
Message-ID: <20230918103046.498@kylheku.com>
References: <udafjf$2joeq$1@dont-email.me> <udigbv$6ddc$2@dont-email.me>
<0M4LM.170545$uEkc.43152@fx35.iad> <udk0hm$h1e9$3@dont-email.me>
<udl0ti$lp5v$4@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <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>
Injection-Date: Mon, 18 Sep 2023 17:34:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6bfaa870470b0ebd2b50ab678df28ccf";
logging-data="1976174"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/F2hw5oLAJYotoKrBNTG2aXvB0JBYJR5w="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:LFLOHYbsXR3itp79C4jDXds3zac=
 by: Kaz Kylheku - Mon, 18 Sep 2023 17:34 UTC

On 2023-09-18, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 17.09.2023 um 21:47 schrieb Richard Damon:
>
>> Why does it need to take into account that an BAD implementation might
>> fail.
>
> With the deferred initialization of a C++ mutex the mutex
> could fail on synchronization even without being bad.

Initialization of a mutex isn't synchronization.

You cannot defer a mutex's initialization until the point where it is
needed for synchronizing something; that is too late.

Well, you can do it, like any other object used for any other purpose,
but you will need another mutex to synchronize that initialization,
and that other mutex has to be already initialized.

Note that in POSIX, you can initialize a mutex with a static
initializer:

static pthread_mutex_t staticMutex = PTHREAD_MUTEX_INITIALIZER;

This does not fail.

For once-only, thread-safe initialization of static objects, an
implementation could use a hidden mutex which can very similarly be
statically initialized, like the POSIX one.

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

<uea1rj$1saml$1@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 19:36:51 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <uea1rj$1saml$1@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>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 17:36:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1faee559a96e8a282152d3a155665a0a";
logging-data="1977045"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ZAeI3xUjHL4DoytiyQGo51XG5pqox9Z8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nZRjmgq0Px5QNbKo8DB2hLTPXbM=
In-Reply-To: <20230918101705.91@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Mon, 18 Sep 2023 17:36 UTC

Am 18.09.2023 um 19:30 schrieb Kaz Kylheku:

> It could be, but a C++ API that does not throw exceptions or return
> error indications wouldn't be able to express support for mutex
> debugging, ...

The constructor is noexcept, so the kernel-part of the mutex for the
slow path needs to be created deferred. This of course can fail and
has _nothing_ to do with mutex debugging.
The mutex which comes along with a static initialization needs to be
created when there's contention on the initialization; this also can
fail, so an exception would be appropriate, preferrably a system_error
as with mutex::lock() and ::unlock().

Re: Thread-safe initialization of static objects

<uea284$1saml$2@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 19:43:32 +0200
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uea284$1saml$2@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>
<20230918103046.498@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 17:43:32 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1faee559a96e8a282152d3a155665a0a";
logging-data="1977045"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198ugdSlgbj56c0Lp2pDbR0lIUVi0dwyfI="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:NxgS/jWV/kcbNKuAxVjyUcrlL+0=
In-Reply-To: <20230918103046.498@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Mon, 18 Sep 2023 17:43 UTC

Am 18.09.2023 um 19:34 schrieb Kaz Kylheku:

> Initialization of a mutex isn't synchronization.

The constructor of mutex is noexept, so if there's contention and
a threads needs to wait it has to create the kernel-part for the
slow path inside lock(). There's no way to have that different
when the constructor is noexcept.

> You cannot defer a mutex's initialization until the point where
> it is needed for synchronizing something; that is too late.

Of course you can and you have to because the std::mutex's constructor
is noxcept. And if there's contention and a thread needs to wait it
creates the kernel sempahore, looks with a CAS if there's already one
created meanwhile and if not the seaphore is attached, otherwise the
own semaphore is destroyed and the mutex attached meanwhile by another
contender is used. The situation that there are multiple semaphores
created and only one is used while the others are destroyed is rather
unlikely, but it might happen.
There's no way to have that different since the construtor is noxcept.
The advantage of that is that some mutexes might be only uses with
their fast paths so never a kernel-semaphore is created so that the
mutex keeps rather lightweight.

Re: Thread-safe initialization of static objects

<20230918104847.796@kylheku.com>

  copy mid

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

  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: Mon, 18 Sep 2023 17:53:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <20230918104847.796@kylheku.com>
References: <udafjf$2joeq$1@dont-email.me> <udigbv$6ddc$2@dont-email.me>
<0M4LM.170545$uEkc.43152@fx35.iad> <udk0hm$h1e9$3@dont-email.me>
<udl0ti$lp5v$4@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <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> <20230917124810.497@kylheku.com>
<ue8mff$q534$1@dont-email.me>
Injection-Date: Mon, 18 Sep 2023 17:53:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6bfaa870470b0ebd2b50ab678df28ccf";
logging-data="1982518"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX194pxJUnaCnXRWIzsBUwqJfZ7fK2AQaZCY="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:yTX3Td5cyGNonRtKATbBq8oTL78=
 by: Kaz Kylheku - Mon, 18 Sep 2023 17:53 UTC

On 2023-09-18, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Rest unread.

I'm afraid that's not very convicing, because the rest of your behavior
shows that you have a voracious appetite for responding to anything and
everything that you're able to.

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

<20230918110147.326@kylheku.com>

  copy mid

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

  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: Mon, 18 Sep 2023 18:07:43 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <20230918110147.326@kylheku.com>
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> <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>
Injection-Date: Mon, 18 Sep 2023 18:07:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6bfaa870470b0ebd2b50ab678df28ccf";
logging-data="1982518"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+arI40Xxd+mCyPxTxzmi+igWuIDEul2MQ="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:snCrataEccXyfpBybUdBCx4du4k=
 by: Kaz Kylheku - Mon, 18 Sep 2023 18:07 UTC

On 2023-09-18, Richard Damon <Richard@Damon-Family.org> wrote:
> On 9/18/23 1:18 AM, Bonita Montero wrote:
>> Am 17.09.2023 um 23:29 schrieb Paavo Helde:
>>
>>> Studying the actual code shows MSVC is using a critical section and
>>> libstc++ is using a futex. These are both single-process only
>>> facilities which cannot fail in ...
>>
>> Specific implementations don't matter because the point is that
>> C++ should honor implementations that can theoretically fail.
>>
>
> Why?
>
> Since it can be done without ever failing, why should the Standard allow
> for failure.

Just for debugging. Same reason why pthread_mutex_lock on POSIX returns int.

If you're sure your program is right, you don't use a debugging mutex
and don't check that int.

An exception would be better because that condition does not go
unchecked just because someone didn't bother.

If a hidden mutex is used for guarding a static initialization,
and static initialization can run arbitrary code (constructors that
can enter static blocks that contain more static initializations)
it is conceivable that the hidden mutexes could deadlock.

In that situation it would be useful if there was an exception or abort.

Just like in POSIX we can have a debugging mutex return EDEADLK.

I don't think that situation would ever be something the application
should handle with some try block, as part of the application logic.
It's something to debug and eliminate.

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

<uea3mr$1sn0e$1@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 20:08:27 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <uea3mr$1sn0e$1@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>
<20230917124810.497@kylheku.com> <ue8mff$q534$1@dont-email.me>
<20230918104847.796@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 18:08:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1faee559a96e8a282152d3a155665a0a";
logging-data="1989646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+n0GoTE8BEm/AgUZQxP6y8xnmp4HJvHhA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:0oWK4xIR2DsNIHF6F/1KNcO3DB4=
Content-Language: de-DE
In-Reply-To: <20230918104847.796@kylheku.com>
 by: Bonita Montero - Mon, 18 Sep 2023 18:08 UTC

Am 18.09.2023 um 19:53 schrieb Kaz Kylheku:

> I'm afraid that's not very convicing, because the rest of your behavior
> shows that you have a voracious appetite for responding to anything and
> everything that you're able to.

I just wanted to correct your wrong assumptions, and I did it well.

Re: Thread-safe initialization of static objects

<uea42g$1sn0e$2@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 20:14:39 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <uea42g$1sn0e$2@dont-email.me>
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> <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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 18:14:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="1faee559a96e8a282152d3a155665a0a";
logging-data="1989646"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19joyU306Da7hbiQcOHBU4oRaahmnAZtCs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:5omsUnQ48ZwF6NxtbP23Oe2Tv2o=
Content-Language: de-DE
In-Reply-To: <20230918110147.326@kylheku.com>
 by: Bonita Montero - Mon, 18 Sep 2023 18:14 UTC

Am 18.09.2023 um 20:07 schrieb Kaz Kylheku:

> Just for debugging. Same reason why pthread_mutex_lock on POSIX returns int.

You won't catch that error while debugging since this could happen only
in situations with very little free memory. In such situations the sys-
tem is swapping and unusable. You won't manage to use a debugger .

> If you're sure your program is right, you don't use a debugging mutex
> and don't check that int.

I've got a function which is called exc_terminate, locking a mutex
is done like that: exc_terminate( [&]() { guard.lock(); } ). The
lock guard is therefore initialized for deferred locking.

> If a hidden mutex is used for guarding a static initialization,
> and static initialization can run arbitrary code (constructors that
> can enter static blocks that contain more static initializations)
> it is conceivable that the hidden mutexes could deadlock.

Local static objects are initialized when the code comes across the
initialization. All other static local objects it refers to have been
declared before, otherwise the static object wouldn't be able to use
them. So there will be never a deadlock.

Re: Thread-safe initialization of static objects

<20230918111327.714@kylheku.com>

  copy mid

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

  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: Mon, 18 Sep 2023 18:15:59 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <20230918111327.714@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> <20230917124810.497@kylheku.com>
<ue8mff$q534$1@dont-email.me> <20230918104847.796@kylheku.com>
<uea3mr$1sn0e$1@dont-email.me>
Injection-Date: Mon, 18 Sep 2023 18:15:59 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6bfaa870470b0ebd2b50ab678df28ccf";
logging-data="1990088"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eRkR/H+y4b13usKYgYU7RAhb9BHHmN9Q="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:QpcjnT4lDj1VTdyViTxPfUqWWTA=
 by: Kaz Kylheku - Mon, 18 Sep 2023 18:15 UTC

On 2023-09-18, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 18.09.2023 um 19:53 schrieb Kaz Kylheku:
>
>> I'm afraid that's not very convicing, because the rest of your behavior
>> shows that you have a voracious appetite for responding to anything and
>> everything that you're able to.
>
> I just wanted to correct your wrong assumptions, and I did it well.

LOL, how well did that work in final exams?

"Dear Prof, you made a wrong assuption in Question 1 and, in my
mind, I responded to it well. I prudently refrained from reading
2 through 20, expecting them to be the same twaddle."

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

<uea7vf$1tgqs$1@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:21:19 -0700
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <uea7vf$1tgqs$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>
<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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:21:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2016092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+taIMr3OpkgVwQHvYrCS7LsoEKrnuT4FY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:3ZQZO02YYQk6Rp/AJTnUOToQt2Y=
In-Reply-To: <ue8lpq$q25a$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:21 UTC

On 9/17/2023 10:05 PM, Bonita Montero wrote:
> Am 17.09.2023 um 21:57 schrieb Chris M. Thomasson:
>
>> I still don't think you know how they work.
>
> You didn't read the paper, not me.
>

I already know how futexes work. In and out.

Re: Thread-safe initialization of static objects

<uea80a$1tgqs$2@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:21:46 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <uea80a$1tgqs$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udigbv$6ddc$2@dont-email.me>
<0M4LM.170545$uEkc.43152@fx35.iad> <udk0hm$h1e9$3@dont-email.me>
<udl0ti$lp5v$4@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:21:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2016092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dVMiPTIlMeYbmc6YKJlrUJpETIButcjs="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:29/1mK/PycJURITd4SDZcvaK7kw=
Content-Language: en-US
In-Reply-To: <20230917123203.524@kylheku.com>
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:21 UTC

On 9/17/2023 12:36 PM, Kaz Kylheku wrote:
> On 2023-09-17, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 17.09.2023 um 21:20 schrieb Kaz Kylheku:
>>
>>> Locking a page is just a state change, not a resource allocation.
>>
>> That's a completely different discussion. The standard should not
>> be based on individual implementations, but should allow for the
>> possibility that the failure of synchronization or the synchroni-
>> zation itself fails.
>
> No it shouldn't. Synchronization that fails for reasons other than
> a bug in the program (deadlock, unlocking un-owned mutex, recursively
> acquiring non-recursive mutex, ...) is a wrongheaded idea, that should
> not and need not be contemplated by any language or library standard
> anywhere, ever.
>
> Futexes are carefully designed not to require resource allocation
> in futex_wait, in light of the above common understanding.
>

Agreed.

Re: Thread-safe initialization of static objects

<uea82d$1tgqs$3@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:22:53 -0700
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <uea82d$1tgqs$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udigbv$6ddc$2@dont-email.me>
<0M4LM.170545$uEkc.43152@fx35.iad> <udk0hm$h1e9$3@dont-email.me>
<udl0ti$lp5v$4@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:22:54 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2016092"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/jo2tKru2L0/+hbLqejncjcHiJNTGWgMY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:iHOXtS/nRVIvvqeDfqS2kSxbvNI=
In-Reply-To: <ue8lv5$q25a$3@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:22 UTC

On 9/17/2023 10:07 PM, Bonita Montero wrote:
> Am 17.09.2023 um 21:47 schrieb Richard Damon:
>
>> Why does it need to take into account that an BAD implementation might
>> fail.
>
> With the deferred initialization of a C++ mutex the mutex
> could fail on synchronization even without being bad.

The impl must make sure to get it right wrt static initialization.

Re: Thread-safe initialization of static objects

<uea847$1tkam$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!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: Mon, 18 Sep 2023 12:23:51 -0700
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <uea847$1tkam$1@dont-email.me>
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> <20230918103046.498@kylheku.com>
<uea284$1saml$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:23:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2019670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kTjQcTjiR+aA+74pq5Uib7oL5iQ+uXvw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:ttu+ib2lLtrvyFCXBYE7Do+xNdE=
In-Reply-To: <uea284$1saml$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:23 UTC

On 9/18/2023 10:43 AM, Bonita Montero wrote:
> Am 18.09.2023 um 19:34 schrieb Kaz Kylheku:
>
>> Initialization of a mutex isn't synchronization.
>
> The constructor of mutex is noexept, so if there's contention and
> a threads needs to wait it has to create the kernel-part for the
> slow path inside lock(). There's no way to have that different
> when the constructor is noexcept.

BARF!

>
>> You cannot defer a mutex's initialization until the point where
>> it is needed for synchronizing something; that is too late.
>
> Of course you can and you have to because the std::mutex's constructor
> is noxcept. And if there's contention and a thread needs to wait it
> creates the kernel sempahore, looks with a CAS if there's already one
> created meanwhile and if not the seaphore is attached, otherwise the
> own semaphore is destroyed and the mutex attached meanwhile by another
> contender is used. The situation that there are multiple semaphores
> created and only one is used while the others are destroyed is rather
> unlikely, but it might happen.
> There's no way to have that different since the construtor is noxcept.
> The advantage of that is that some mutexes might be only uses with
> their fast paths so never a kernel-semaphore is created so that the
> mutex keeps rather lightweight.
>
>

Re: Thread-safe initialization of static objects

<uea886$1tkam$2@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:25:57 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uea886$1tkam$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udigbv$6ddc$2@dont-email.me>
<0M4LM.170545$uEkc.43152@fx35.iad> <udk0hm$h1e9$3@dont-email.me>
<udl0ti$lp5v$4@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <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> <20230917124810.497@kylheku.com>
<ue8mff$q534$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:25:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2019670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+9DoM9y99lTSBEtYplhOxfidg8vSL/PVI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:VYJ9JhkzqqloKYrjOdweZOp13TQ=
Content-Language: en-US
In-Reply-To: <ue8mff$q534$1@dont-email.me>
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:25 UTC

On 9/17/2023 10:16 PM, Bonita Montero wrote:
> Am 17.09.2023 um 21:49 schrieb Kaz Kylheku:
>
>> It's one that you started ...
>
> No, I didn't start it, Chris did. And at this point it was
> no longer a question of whether synchronization could fail.
>
> Rest unread.
>

I said that I have my doubts on your ability to understand futexes. You
have made some really strange false statements here. Sorry, is not my
fault when I detect them. Sorry, Bonita.

Re: Thread-safe initialization of static objects

<uea89r$1tkam$3@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:26:51 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <uea89r$1tkam$3@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>
<20230917124810.497@kylheku.com> <ue8mff$q534$1@dont-email.me>
<20230918104847.796@kylheku.com> <uea3mr$1sn0e$1@dont-email.me>
<20230918111327.714@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:26:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2019670"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Fz5jdvbu+0HZQv7Z1SOl7MK8wp/lkux4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:/Krj63JmO4gZHL6HD+n+CJI8EhE=
In-Reply-To: <20230918111327.714@kylheku.com>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:26 UTC

On 9/18/2023 11:15 AM, Kaz Kylheku wrote:
> On 2023-09-18, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 18.09.2023 um 19:53 schrieb Kaz Kylheku:
>>
>>> I'm afraid that's not very convicing, because the rest of your behavior
>>> shows that you have a voracious appetite for responding to anything and
>>> everything that you're able to.
>>
>> I just wanted to correct your wrong assumptions, and I did it well.
>
> LOL, how well did that work in final exams?
>
> "Dear Prof, you made a wrong assuption in Question 1 and, in my
> mind, I responded to it well. I prudently refrained from reading
> 2 through 20, expecting them to be the same twaddle."
>

Bonita, the beautiful Toll of Troll?

Re: Thread-safe initialization of static objects

<uea8vt$1tpp8$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!i2pn.org!usenet.goja.nl.eu.org!3.eu.feeder.erje.net!feeder.erje.net!news.szaf.org!gandalf.srv.welterde.de!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: Mon, 18 Sep 2023 12:38:35 -0700
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <uea8vt$1tpp8$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> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <DjENM.51886$8XGa.26896@fx17.iad>
<ue77ul$eiv3$1@dont-email.me> <8SGNM.4844$3lL1.4797@fx47.iad>
<ue7f3i$frod$1@dont-email.me> <20230917112958.807@kylheku.com>
<ue7hsb$g7tm$5@dont-email.me> <ue7hvn$gach$3@dont-email.me>
<ue7ib9$gcfr$1@dont-email.me> <ue7n7p$hc5g$1@dont-email.me>
<ue8m2d$q25a$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:38:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2025256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+k0KlBtwFqC50eCnW6qk2GHJnIZKl7Qss="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:En94oLxWWJ3RXrClHCeZhis+/xU=
In-Reply-To: <ue8m2d$q25a$4@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:38 UTC

On 9/17/2023 10:09 PM, Bonita Montero wrote:
> Am 17.09.2023 um 22:23 schrieb Chris M. Thomasson:
>
>> I personally consider contention to be a so-called slow-path. ...
>
> The futex part is to make the slow path faster.
>

;^o

A futex is meant to handle a slow-path when a user algorithm finally
decides that it must block in the kernel. The futex can be thought of as
a nice, sort of, "condition variable" for algorithms. A fath-path can be
lock/wait-free indeed, however a futex gives them ability to actually
wait in the kernel.

A futex means that the user algorithm can use addresses based sync and
not have to worry about creating and destroying kernel resources. Its
not really about making the slow path "faster". Wrt the user algorithm,
a slow-path that must use the kernel is slow by default. We try to avoid
slow-paths. One simple way is that of an adaptive mutex.

I actually created a futex emulation that used wait queues, however...
It's all in userspace and thus can basically only honor SCHED_OTHER.

Btw, take a good look at the benaphore. Its a way to try to avoid calls
into the kernel. This is not using a futex, but a semaphore iirc:

https://www.haiku-os.org/legacy-docs/benewsletter/Issue1-26.html#Engineering1-26

A futex is a lot more flexible than this setup.

Re: Thread-safe initialization of static objects

<uea91a$1tpp8$2@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:39:21 -0700
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <uea91a$1tpp8$2@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>
<DjENM.51886$8XGa.26896@fx17.iad> <ue77ul$eiv3$1@dont-email.me>
<8SGNM.4844$3lL1.4797@fx47.iad> <ue7f3i$frod$1@dont-email.me>
<20230917112958.807@kylheku.com> <ue7hsb$g7tm$5@dont-email.me>
<20230917122041.465@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:39:22 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2025256"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18eLhcHjC8qF+3mlafUYmvzLN9/TxENRCU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:tCrCdyZCSL6pRO2HKU1daG+iOF8=
Content-Language: en-US
In-Reply-To: <20230917122041.465@kylheku.com>
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:39 UTC

On 9/17/2023 12:22 PM, Kaz Kylheku wrote:
> On 2023-09-17, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 17.09.2023 um 20:49 schrieb Kaz Kylheku:
>>
>>> When mutexes fail, it is due to bugs in the application. In that case,
>>> if that happens at global init time, the program can just abort.
>>
>> C++ mutexes always have a delayed initialitation since the constructor
>> is noexcept. So the semaphore behind the mutex which backs contention
>> is created on synchonzation, which may fail.
>>
>>> In POSIX, ..
>>
>> It doesn't matter what a specific operating system says about that,
>
> s/operating system/international standard for operating system family/
>
>> Rest unread.
>
> Aha; I think this is your approach to documentation also.
>

Bonita might be morphing into troll mode again. Not just insult mode.

Re: Thread-safe initialization of static objects

<20230918123203.723@kylheku.com>

  copy mid

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

  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: Mon, 18 Sep 2023 19:42:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 77
Message-ID: <20230918123203.723@kylheku.com>
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>
<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>
Injection-Date: Mon, 18 Sep 2023 19:42:19 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6bfaa870470b0ebd2b50ab678df28ccf";
logging-data="2026553"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19GIrgomdUI0m2EDOHzlPC3QWOraW05IvM="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:nfsKVqBiRlq2I4AwYDnPxu40czo=
 by: Kaz Kylheku - Mon, 18 Sep 2023 19:42 UTC

On 2023-09-18, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 18.09.2023 um 20:07 schrieb Kaz Kylheku:
>
>> Just for debugging. Same reason why pthread_mutex_lock on POSIX returns int.
>
> You won't catch that error while debugging since this could happen only

I've no idea what "that error" refers to.

> in situations with very little free memory. In such situations the sys-
> tem is swapping and unusable. You won't manage to use a debugger .

I'm not aware of any mutex-specific error that has to do with low
memory, and didn't mention one.

>> If a hidden mutex is used for guarding a static initialization,
>> and static initialization can run arbitrary code (constructors that
>> can enter static blocks that contain more static initializations)
>> it is conceivable that the hidden mutexes could deadlock.
>
> Local static objects are initialized when the code comes across the
> initialization. All other static local objects it refers to have been
> declared before, otherwise the static object wouldn't be able to use
> them. So there will be never a deadlock.

That is false:

struct static_thing
{
// constructor calls function pointer argument
static_thing(void (*)(pfn))
{
pfn();
}
};

void A(void)
{
static_thing o(B);
}

void B(void)
{
static_thing o(A);
}

Suppose A and B have not been called yet. We have two
threads, T1 and T2. T1 calls A() at around the same time
as T2 calls B().

T1 and T2 both lock the respective hidden mutexes that guard
the initialization of the two static objects. Let's call those
the "A mutex" and "B mutex".

While holding the A mutex, T1 then calls B() through the pointer,
and blocks on trying to acquire the B mutex. Reciprocally, T2 calls A
while holding the B mutex and blocks on the A mutex.

This is a classic deadlock due to opposite acquisition of the same
resources.

Since blocks with static initializations can be anywhere and
are entered by any thread in any order, and the constructor
calls can do it too, there is a threat.

(There will likely be a "double checked locking pattern" at play,
but that doesn't solve the deadlock. T1 will call B() where it
sees that the flag has not been set indicating that o has
been constructed, and so it will go through the slow path and
hit the mutex.)

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

<uea9hr$1ts6c$2@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:48:11 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <uea9hr$1ts6c$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udigbv$6ddc$2@dont-email.me>
<0M4LM.170545$uEkc.43152@fx35.iad> <udk0hm$h1e9$3@dont-email.me>
<udl0ti$lp5v$4@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:48:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2027724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192nRw41eRDtmNkq97sq3IwrKtYw7Luh1Q="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:9nX+6vWIovTbg6KSPr9+ymwNOVk=
In-Reply-To: <ue8mn0$q534$4@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:48 UTC

On 9/17/2023 10:20 PM, Bonita Montero wrote:
> Am 17.09.2023 um 22:01 schrieb Pavel:
>
>> Of course you don't show that the synchronization primitives that are
>> used for static initialization are mutexes.
>
> Call it mutex or whatever: the standard requires that contenders
> sleep in place,

Huh?

> and that's only possible with something that works
> like a mutex.
>

wow... For some reason I just heard the sound of a toilet flushing. Over
your head?

Re: Thread-safe initialization of static objects

<uea9ks$1ts6c$3@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:49:48 -0700
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uea9ks$1ts6c$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udigbv$6ddc$2@dont-email.me>
<0M4LM.170545$uEkc.43152@fx35.iad> <udk0hm$h1e9$3@dont-email.me>
<udl0ti$lp5v$4@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:49:48 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2027724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19pspq/NwZ2qttrbEU5KJaq/vPbyJE24UU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:WZNxY7LUiO7yHS3T5qAIC7n9LBs=
Content-Language: en-US
In-Reply-To: <ue8mid$q534$2@dont-email.me>
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:49 UTC

On 9/17/2023 10:18 PM, Bonita Montero wrote:
> Am 17.09.2023 um 23:29 schrieb Paavo Helde:
>
>> Studying the actual code shows MSVC is using a critical section and
>> libstc++ is using a futex. These are both single-process only
>> facilities which cannot fail in ...
>
> Specific implementations don't matter because the point is that
> C++ should honor implementations that can theoretically fail.
>

Humm... Fail for what reasons? User? Humm...

Re: Thread-safe initialization of static objects

<ueaa0n$1ts6c$4@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:56:07 -0700
Organization: A noiseless patient Spider
Lines: 61
Message-ID: <ueaa0n$1ts6c$4@dont-email.me>
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> <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>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:56:07 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2027724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19shHyKg39Q6xnV8koHDe8+nQnjQ67RZhw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:6UDqs6qqY7jF8UknGAgVXfcKoyk=
Content-Language: en-US
In-Reply-To: <20230918110147.326@kylheku.com>
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:56 UTC

On 9/18/2023 11:07 AM, Kaz Kylheku wrote:
> On 2023-09-18, Richard Damon <Richard@Damon-Family.org> wrote:
>> On 9/18/23 1:18 AM, Bonita Montero wrote:
>>> Am 17.09.2023 um 23:29 schrieb Paavo Helde:
>>>
>>>> Studying the actual code shows MSVC is using a critical section and
>>>> libstc++ is using a futex. These are both single-process only
>>>> facilities which cannot fail in ...
>>>
>>> Specific implementations don't matter because the point is that
>>> C++ should honor implementations that can theoretically fail.
>>>
>>
>> Why?
>>
>> Since it can be done without ever failing, why should the Standard allow
>> for failure.
>
> Just for debugging. Same reason why pthread_mutex_lock on POSIX returns int.
>
> If you're sure your program is right, you don't use a debugging mutex
> and don't check that int.
>
> An exception would be better because that condition does not go
> unchecked just because someone didn't bother.
>
> If a hidden mutex is used for guarding a static initialization,
> and static initialization can run arbitrary code (constructors that
> can enter static blocks that contain more static initializations)
> it is conceivable that the hidden mutexes could deadlock.

If a deadlock occurs wrt static initialization _itself_, well, that
should be the fault of the impl, yikes!. Although, if the user is not
that skilled, and makes the object that is being statically initialized
do something that makes itself deadlock in a ctor or something. Well,
that is on the user, not the impl....

Fair enough?

> In that situation it would be useful if there was an exception or abort.
>
> Just like in POSIX we can have a debugging mutex return EDEADLK.
>
> I don't think that situation would ever be something the application
> should handle with some try block, as part of the application logic.
> It's something to debug and eliminate.
>

Right. The impl shall get it right, (tm). Also, the other part of the
contract, is that the user should get it right as well. It kind of seems
like Bonita wants C/C++ to put proverbial "corks on the forks" for user
code:

A C/C++ impl should handle all, and think that its users are all somehow
akin to Ruprecht in the following scene:

https://youtu.be/SKDX-qJaJ08

Why is the cork on the fork... To prevent C and/or C++ from hurting
himself... ;^) lol.

Re: Thread-safe initialization of static objects

<ueaa2p$1ts6c$5@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 12:57:13 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <ueaa2p$1ts6c$5@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <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> <mBZNM.58210$8XGa.27400@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 19:57:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2027724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TVltviiGCWOlaJMOAImv4KhsG7wK0ia8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:rtMZ8XuGte1tfjAwgWOA/+2Cfo8=
In-Reply-To: <mBZNM.58210$8XGa.27400@fx17.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 19:57 UTC

On 9/18/2023 7:59 AM, Scott Lurndal wrote:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 17.09.2023 um 23:29 schrieb Paavo Helde:
>>
>>> Studying the actual code shows MSVC is using a critical section and
>>> libstc++ is using a futex. These are both single-process only facilities
>>> which cannot fail in ...
>>
>> Specific implementations don't matter because the point is that
>> C++ should honor implementations that can theoretically fail.
>
> Feel free to submit a proposal to the C++ standard committee.
>
> Since everyone particpating in this discussion on comp.lang.c++
> seems to take the opposite view that you do, I don't believe you'll
> have much success in your proposal.

Bonita, is an interesting person, indeed.

Re: Thread-safe initialization of static objects

<ueaaa7$1u08o$1@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 13:01:11 -0700
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <ueaaa7$1u08o$1@dont-email.me>
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> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <oHHNM.23271$H8td.1529@fx10.iad>
<ue7hnl$g7tm$4@dont-email.me> <kFINM.23274$H8td.18289@fx10.iad>
<ue8mju$q534$3@dont-email.me> <H7XNM.16066$JX2f.9443@fx13.iad>
<ue9gq5$1ousp$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 20:01:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2031896"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/xqhIBrQMA8JEi/Cr/bQjmDGHHlFfjuMw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:bVZYFYa/VmRdB8GupUG0059LDwg=
In-Reply-To: <ue9gq5$1ousp$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 20:01 UTC

On 9/18/2023 5:45 AM, Bonita Montero wrote:
> Am 18.09.2023 um 14:11 schrieb Richard Damon:
>
>> You are assuming is uses the object the OS is calling a "Mutex", which
>> is an object that works inter-process, but we don't need anything that
>> powerful.
>
> When I talk about a mutex in the context of C++, especially when
> it comes to static initialization, it should be clear that I don't
> mean mutexes that are "inter-process".
>
>> So, the alternative to using a Windows Mutex is using something else.
>> Something which can't fail.
>
> At least the creation of the kernel resource for the slow path of
> the mutex can fail. And under Windows even a WaitForSingleObject(),
> which usually is used for the slow path, can fail for not entirely
> specified reasons.

Huh?

>
> I had the same discussion on Stack Overflow and had the same objections,
> but lastly the people with these objections saw that what I was saying
> made sense. Here, however, there are only idiots.
>
> I don't know what the fuss is about: if waiting for a std::mutex
> can fail, the people who developed the standard figured that the
> operating system part could fail. Accordingly, there is an exception
> for std::mutex if you lock it. If you look at this consistently,
> static initialization should also be able to throw an exception
> for the same reason because the same kernel mechanisms are behind
> it.

Re: Thread-safe initialization of static objects

<ueaabk$1ts6c$6@dont-email.me>

  copy mid

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

  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: Mon, 18 Sep 2023 13:01:56 -0700
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <ueaabk$1ts6c$6@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>
<oHHNM.23271$H8td.1529@fx10.iad> <ue7hnl$g7tm$4@dont-email.me>
<kFINM.23274$H8td.18289@fx10.iad> <ue8mju$q534$3@dont-email.me>
<H7XNM.16066$JX2f.9443@fx13.iad> <ue9gq5$1ousp$2@dont-email.me>
<ueaaa7$1u08o$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 18 Sep 2023 20:01:56 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="dbd0edff1a203ab30b2e978110ba1d77";
logging-data="2027724"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192K+jj+uuwkoc+D5VXWmXyfNe9a2wlKA0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:5/ls/e8EV1Fny1tW6+bCYW/HHZQ=
In-Reply-To: <ueaaa7$1u08o$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Mon, 18 Sep 2023 20:01 UTC

On 9/18/2023 1:01 PM, Chris M. Thomasson wrote:
> On 9/18/2023 5:45 AM, Bonita Montero wrote:
>> Am 18.09.2023 um 14:11 schrieb Richard Damon:
>>
>>> You are assuming is uses the object the OS is calling a "Mutex",
>>> which is an object that works inter-process, but we don't need
>>> anything that powerful.
>>
>> When I talk about a mutex in the context of C++, especially when
>> it comes to static initialization, it should be clear that I don't
>> mean mutexes that are "inter-process".
>>
>>> So, the alternative to using a Windows Mutex is using something else.
>>> Something which can't fail.
>>
>> At least the creation of the kernel resource for the slow path of
>> the mutex can fail. And under Windows even a WaitForSingleObject(),
>> which usually is used for the slow path, can fail for not entirely
>> specified reasons.
>
> Huh?

An impl SHALL get static initialization right. Leave it up the to user
to deadlock everything. ;^o

>
>
>>
>> I had the same discussion on Stack Overflow and had the same objections,
>> but lastly the people with these objections saw that what I was saying
>> made sense. Here, however, there are only idiots.
>>
>> I don't know what the fuss is about: if waiting for a std::mutex
>> can fail, the people who developed the standard figured that the
>> operating system part could fail. Accordingly, there is an exception
>> for std::mutex if you lock it. If you look at this consistently,
>> static initialization should also be able to throw an exception
>> for the same reason because the same kernel mechanisms are behind
>> it.
>

Re: Thread-safe initialization of static objects

<8H5OM.30728$Yxl8.29787@fx14.iad>

  copy mid

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

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

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

Agree, good names are important for readability.

The issue with POSIX mutex is that there is only one C type for all
mutex types, pthread_mutex_t so at least one dispatch is necessary (and,
at least in the current Linux implementation, many dispatches are done).

>
> I find that a more descriptive name can help wrt reading code created by
> somebody else. Humm... Actaly, I do not like to use recursive mutexes
> very much (if at all) because I have had to debug some other peoples
> "nightmare" code that recursed, and caused a deadlock around four locks
> deep.... It technically was not the fault of the recursion ability, but
> it was an error on the programmers side. The name of the lock was
> something like (object.m_lock), it was vague and I did not even know it
> recursed until I took a deeper look at the damn "nightmare" code. So,
> iirc, I said out loud, name it something else... How about:
>
> object.m_lock_recusive__never__use__
>
> and got a laugh from the room. :^)
>
>
>
>
>
>>
>> but each of these can be additionally either robust or non-robust
>> (and, pthread_mutex_lock is supposed to behave differently for some
>> combinations of type and robustness). Unless of course we dispatch to
>> a cartesian product of options (which is not impossible, but see below).
>>
>> And, lastly, the above are all hypotheticals and the actual code (see
>> e.g.
>> https://codebrowser.dev/glibc/glibc/nptl/pthread_mutex_lock.c.html )
>> is slightly messier than the best organized implementation possible.
>>  From practical perspective, I would expect that someone implementing
>> a thread-safe static initialization in a C++ compiler has their mouth
>> full with the tasks other than improving the existing pthread_mutex
>> (or pthread_once) implementation as a distraction; at most (I would
>> speculate), they would take a quick (~5 min) look into the API and the
>> available code of the existing established synchronization primitives
>> and decide which one is likely to better fit their spec and be faster
>> as-is to use to implement that pesky initialization spec. In this
>> scenario, I would guess that pthread_once_t would win the beauty
>> contest and get selected.
>>
>> And, sure enough, (likely due to no feature bloat) the *existing*
>> pthread_once implementation code is much cleaner (see
>> https://codebrowser.dev/glibc/glibc/nptl/pthread_once.c.html) and at
>> first glance should be measurably faster.
>>
>> I guess, instead of guessing, (no pun untended again), we could just
>> disassemble some static initialization and see how it's done in, say,
>> gcc. Maybe later...
>>
>>> So, wrt windows, an intra-process mutex can be a CRITICAL_SECTION. Or
>>> an inter-process as a mutex HANDLE.
>>>
>>> https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-createmutexexa
>>>
>>>
>>> Wrt the inter-process route we may need to deal with WAIT_ABANDONED,
>>> or EOWNERDEAD wrt POSIX. So we create different types:
>>>
>>>
>>> struct intra_process_mutex
>>> {
>>>      CRITICAL_SECTION m_os_lock;
>>> };
>>>
>>>
>>> struct inter_process_mutex
>>> {
>>>      HANDLE m_os_lock;
>>> };
>>>
>>> struct inter_process_mutex_robust
>>> {
>>>      HANDLE m_os_lock;
>>> };
>>>
>>>
>>>
>>> These simple types can be rather easy to reason about. Wrt POSIX, the
>>> different types would be:
>>>
>>>
>>> struct intra_process_mutex
>>> {
>>>      pthread_mutex_t m_os_lock;
>>> };
>>>
>>>
>>> struct inter_process_mutex
>>> {
>>>      pthread_mutex_t m_os_lock;
>>> };
>>>
>>> struct inter_process_mutex_robust
>>> {
>>>      pthread_mutex_t m_os_lock;
>>> };
>>>
>>>
>>> The point is trying to organize things a bit here.
>>>
>>> Sound somewhat decent?
>>>
>>>
>>>>
>>>>> so it is possible, so you can't say the Standard is asking for
>>>>> impossible behavior, thus any "optimizations" that don't meet that
>>>>> defined behavior are just WRONG.
>>>>>
>>>>> Saying something wrong must be made right is just WRONG, so you are
>>>>> WRONG in your claim.
>>>>>
>>>>> PERIOD.
>>>>
>>>
>>
>


Click here to read the complete article
Re: Thread-safe initialization of static objects

<hK5OM.30729$Yxl8.9621@fx14.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!1.us.feeder.erje.net!feeder.erje.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
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> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me>
From: pauldontspamtolk@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <uea1rj$1saml$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 23
Message-ID: <hK5OM.30729$Yxl8.9621@fx14.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Tue, 19 Sep 2023 00:15:09 UTC
Date: Mon, 18 Sep 2023 20:15:09 -0400
X-Received-Bytes: 2463
 by: Pavel - Tue, 19 Sep 2023 00:15 UTC

Bonita Montero wrote:
> Am 18.09.2023 um 19:30 schrieb Kaz Kylheku:
>
>> It could be, but a C++ API that does not throw exceptions or return
>> error indications wouldn't be able to express support for mutex
>> debugging, ...
>
> The constructor is noexcept, so the kernel-part of the mutex for the
> slow path needs to be created deferred.
Or, when there is nothing to create, there is nothing to defer,

> This of course can fail
and, of course, nothing can fail.

> and
> has _nothing_ to do with mutex debugging.
> The mutex which comes along with a static initialization needs to be
> created when there's contention on the initialization; this also can
> fail, so an exception would be appropriate, preferrably a system_error
> as with mutex::lock() and ::unlock().
>
>


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

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor