Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"I'm a mean green mother from outer space" -- Audrey II, The Little Shop of Horrors


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

<mzkPM.16155$ugs.3977@fx36.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx36.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad> <ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad> <ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad> <ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad> <ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad> <uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad> <uej631$3uji0$4@dont-email.me>
Lines: 12
Message-ID: <mzkPM.16155$ugs.3977@fx36.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 22 Sep 2023 17:56:34 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 22 Sep 2023 17:56:34 GMT
X-Received-Bytes: 1596
 by: Scott Lurndal - Fri, 22 Sep 2023 17:56 UTC

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

Why on earth would the run-time/dynamic loader use a C++ mutex
instead of an implementation-defined primitive (e.g. pthread_once,
pthread_mutex_t) which are easily statically initalized?

Re: Thread-safe initialization of static objects

<uekler$bqj8$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 20:12:45 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uekler$bqj8$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 22 Sep 2023 18:12:44 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="667bcb529bd651b387f543a5d4231de5";
logging-data="387688"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19hakS+rZFi0BLHQ8cPNIPRTqk7VBzfTMA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:3NMKbRPCw0ZPR4C+hAR5jjtjv98=
In-Reply-To: <mzkPM.16155$ugs.3977@fx36.iad>
Content-Language: de-DE
 by: Bonita Montero - Fri, 22 Sep 2023 18:12 UTC

Am 22.09.2023 um 19:56 schrieb Scott Lurndal:

> Why on earth would the run-time/dynamic loader use a C++ mutex
> instead of an implementation-defined primitive (e.g. pthread_once,
> pthread_mutex_t) which are easily statically initalized?

pthread_mutex_init() can fail so you can't used it inside the std::mutex
constructor. Using pthread_mutex_init() delayed inside ::lock is too
late because you need a locking-counter/-flag at this moment, but this
is created internally along with pthread_mutex_init().

Re: Thread-safe initialization of static objects

<20230922105014.587@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 18:14:10 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <20230922105014.587@kylheku.com>
References: <udafjf$2joeq$1@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <aJINM.23275$H8td.10140@fx10.iad>
<ue8lv5$q25a$3@dont-email.me> <th7PM.6493$wGe2.6301@fx03.iad>
<uej5tu$3uji0$3@dont-email.me> <20230921220955.181@kylheku.com>
<uejdio$2g4g$1@dont-email.me> <uekiup$bci8$1@dont-email.me>
<uekj9c$bfh8$1@dont-email.me>
Injection-Date: Fri, 22 Sep 2023 18:14:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="390562"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19KkG2eZInxAORgN4DHJj/cWBCxmNuPjFs="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:qH+v8iISGgMNNklLPg6pw7HD2iY=
 by: Kaz Kylheku - Fri, 22 Sep 2023 18:14 UTC

On 2023-09-22, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 22.09.2023 um 19:30 schrieb Chris M. Thomasson:
>
>> Why do you say that!? A futex does not make the user code create any
>> kernel resources. You are a fairly stubborn person! :^)
>
> A futex is a replacement for the slow path, replacing a binary
> semaphore. It requires to make the futexes's address to be read
> -only to trap accesses and it requires a waiter's queue inside
> the kernel.

Futexes do not trap accesses. That would make them too slow to be
useful, and defeat their entire purpose, which is to avoid unnecessary
trips to the kernel! How can you not have an intuition for this,
given all the multithreading know-how and experience you claim to have?

The kernel does not know when a futex location is touched; it
is not informed.

That's why there is an explicit futex wake operation.

> Your misconception is that you think the futex is pure userspace,
> but the difference is just that there's no explicit kernel-call
> but a MMU-trap, which is faster on most CPUs than a explicit
> kernel-call. So a futex is not possible without a MMU, documented
> here: https://bugzilla.kernel.org/show_bug.cgi?id=78881

The bug is reported against some MMU-less sytem, claiming that
FUTEX_WAIT and FUTEX_WAKE are returning -EFAULT.
https://bugzilla.kernel.org/show_bug.cgi?id=78881

The bug reporter acknowledges that the issue does not affect
private futexes; i.e. they are working on their MMU-less system!

It's happening in the get_futex_key function, which has to
obtain a stable hash key from a futex address.

Futexes interact with virtual memory because virtual memory
has the potential to create aliases.

The same futex location can be shared memory which can exist
at different addresses in different processes (or even
the same process).

The same futex can have more than one virtual address. See the problem?
The futex has to hash to the same wait queue, in spite of having
different virtual addresses. So what that means is that we cannot just
naively hash the virtual address to get a futex key for the hash.

The above bug says that this resolution is not working.

The bug was opened nine years ago and is still NEW probably because it
is not easily fixable. Without a MMU, futex sharing via shared memory
doesn't make sense. About all you can do is report a different error
than -EFAULT, like -EOPNOTSUPP or whatever.

(I'm surprised nobody replied to the bug to at least say that.)

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

<20230922111441.730@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 18:38:46 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 54
Message-ID: <20230922111441.730@kylheku.com>
References: <udafjf$2joeq$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
<uekler$bqj8$1@dont-email.me>
Injection-Date: Fri, 22 Sep 2023 18:38:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="178c3857704d977ee6ffe0460286225b";
logging-data="398351"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Cg7o254DNYNYbO3xQEoFNjhCQ/FxTie0="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:TA1Dl2i7hJgFOIPHRoe+22vqDtw=
 by: Kaz Kylheku - Fri, 22 Sep 2023 18:38 UTC

On 2023-09-22, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 22.09.2023 um 19:56 schrieb Scott Lurndal:
>
>> Why on earth would the run-time/dynamic loader use a C++ mutex
>> instead of an implementation-defined primitive (e.g. pthread_once,
>> pthread_mutex_t) which are easily statically initalized?
>
> pthread_mutex_init() can fail so you can't used it inside the std::mutex
> constructor.

POSIX provides a PTHREAD_MUTEX_INITIALIZER which lets you do just this:

pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;

In a C++ mutex class based on pthread_mutex_t we can do

class cpp_mutex {
private:
pthread_mutex_t mtx;

public:
cpp_mutex() : mtx(PTHREAD_MUTEX_INITIALIZER)
{
}
};

(Note that the POSIX standard used to say that the
PTHREAD_MUTEX_INITIALIZER could be used for statically allocated
mutexes. That wording no longer appears.)

pthread_mutex_init can fail, but usually doesn't. If you use NULL
attributes (i.e. not making any funny mutex type, like process-shared
robust or whatever) and haven't done anything wrong, you will not get a
nonzero return.

The API allows for resource-related errors like EAGAIN, but a mutex
created with default attributes will pretty much be the same as
one set up with PTHREAD_MUTEX_INITIALIZER. Implementations have to
support that and so they figure out how to have a basic mutex that
doesn't fail on construction.

Note that resource allocation cannot be deferred to lock acquisition
time; no resource-related error codes are specified for
pthread_mutex_lock.

See POSIX here:

https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html

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

<IsoPM.20139$wO91.15127@fx39.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx39.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad> <ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad> <ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad> <ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad> <ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad> <uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad> <uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad> <uekler$bqj8$1@dont-email.me>
Lines: 21
Message-ID: <IsoPM.20139$wO91.15127@fx39.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 22 Sep 2023 22:22:32 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 22 Sep 2023 22:22:32 GMT
X-Received-Bytes: 1955
 by: Scott Lurndal - Fri, 22 Sep 2023 22:22 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 22.09.2023 um 19:56 schrieb Scott Lurndal:
>
>> Why on earth would the run-time/dynamic loader use a C++ mutex
>> instead of an implementation-defined primitive (e.g. pthread_once,
>> pthread_mutex_t) which are easily statically initalized?
>
>pthread_mutex_init() can fail

That is beside the point. The mutex can be statically initialized
and the pthread_mutex_init call is unnecessary. You've been informed
of this point at least a half dozen times in this thread alone.

SYNOPSIS
#include <pthread.h>

int pthread_mutex_destroy(pthread_mutex_t *mutex);
int pthread_mutex_init(pthread_mutex_t *restrict mutex,
const pthread_mutexattr_t *restrict attr);
pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;

Re: Thread-safe initialization of static objects

<jBoPM.25452$fUu6.14009@fx47.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Thread-safe initialization of static objects
Content-Language: en-US
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me> <1GhOM.7399$H0Ge.6907@fx05.iad>
<uecac1$2cj86$1@dont-email.me> <iwpOM.265$Sn81.181@fx08.iad>
<uedp93$2orvq$2@dont-email.me> <k4BOM.2058$TwR4.78@fx46.iad>
<ueeret$2upib$1@dont-email.me> <JCKOM.83797$2ph4.24937@fx14.iad>
<uege3r$3bfsj$2@dont-email.me> <ueggh5$3bq3f$1@dont-email.me>
<uegsdo$3dj0r$1@dont-email.me> <uei1g6$3l13h$2@dont-email.me>
<ueiu42$3tima$1@dont-email.me> <eE7PM.16350$3vM.3605@fx37.iad>
<uej5q1$3uji0$1@dont-email.me> <gWePM.25327$fUu6.21270@fx47.iad>
<uek0g4$7fl1$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <uek0g4$7fl1$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 25
Message-ID: <jBoPM.25452$fUu6.14009@fx47.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Fri, 22 Sep 2023 18:31:43 -0400
X-Received-Bytes: 2914
 by: Richard Damon - Fri, 22 Sep 2023 22:31 UTC

On 9/22/23 8:15 AM, Bonita Montero wrote:
> Am 22.09.2023 um 13:31 schrieb Richard Damon:
>
>> Just shows that you don't actually know what we are talking about.
>
> We're talking about if everything different like a mutex is acceptable
> here. And it isn't. Yielding might have a too high delay under load
> and spinning is dangerous in userspace because of what I've said.
>

Which, since it has been explained WHY your arguments are just wrong,
showing that you don't know what you are talking about, since all your
arguements are against "Strawmen" and not the actual thing being talked
about, you are just showing your ignorance.

You seem to be claiming that because you can't figure out a reasonable
way to do it with what you understand, the Standard needs to be changed
to allow provide lessor promises to the programmer.

Since there ARE implementation that actually meet the requirements, you
are obviously wrong that they can't be meet with a "reasonable" performance.

The fact that you are too stupid to understand how these things actually
work and give performant results doesn't mean they don't do it. The fact
that they do shows your ignorance.

Re: Thread-safe initialization of static objects

<uelask$fp8c$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 17:18:28 -0700
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <uelask$fp8c$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad> <uecac1$2cj86$1@dont-email.me>
<iwpOM.265$Sn81.181@fx08.iad> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<DUVOM.87557$noZ7.33800@fx13.iad> <uehdjj$3h8me$3@dont-email.me>
<uehf2o$3hkm3$2@dont-email.me> <uehj9d$3idng$1@dont-email.me>
<uei1rg$3l13h$4@dont-email.me> <ueiu5b$3tima$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 00:18:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="517388"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RNhDDY8t3KpbLG4zNw80HZn6MV/KUlMc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:FI7QjLMdu+uGsxC7h8NLWfvAmY0=
In-Reply-To: <ueiu5b$3tima$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 00:18 UTC

On 9/21/2023 7:29 PM, Bonita Montero wrote:
> Am 21.09.2023 um 20:25 schrieb Chris M. Thomasson:
>> On 9/21/2023 7:17 AM, Bonita Montero wrote:
>>> Am 21.09.2023 um 15:05 schrieb David Brown:
>>>
>>>> "Yield" won't take a timeslice unless there is something else of the
>>>> same priority, waiting to run on the same core. ...
>>>
>>> Ok, you're right, but the code would be still unacceptable under load.
>>>
>>
>> Wait, are you talking about a _pure_ spin lock in user space here?
>> For some reason you seem to be struggling with adaptive backoffs, ...
>
> No, we were discussing yielding.
>
>

What about an algorithm that can try to do some other non related work
instead of yielding? I remember learning about this technique many moons
ago over on comp.arch. I think it was from Lynn and Ann Wheeler? They
just happen to be VERY smart and saturated with experience. I cannot
remember their last name right now it think its Wheeler. Argh! Those
posts might be hard to find.

Re: Thread-safe initialization of static objects

<uelb1m$fp8c$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 17:21:09 -0700
Organization: A noiseless patient Spider
Lines: 22
Message-ID: <uelb1m$fp8c$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad> <uecac1$2cj86$1@dont-email.me>
<iwpOM.265$Sn81.181@fx08.iad> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<DUVOM.87557$noZ7.33800@fx13.iad> <uehdjj$3h8me$3@dont-email.me>
<uei1je$3l13h$3@dont-email.me> <ueiu6e$3tima$3@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 00:21:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="517388"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19dQSeM3tJgQ67VfCnhA3Iq5JGxNeoa8cc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:D1syZu+tx7bwMZ6Uu1yx6l+J3eQ=
Content-Language: en-US
In-Reply-To: <ueiu6e$3tima$3@dont-email.me>
 by: Chris M. Thomasson - Sat, 23 Sep 2023 00:21 UTC

On 9/21/2023 7:29 PM, Bonita Montero wrote:
> Am 21.09.2023 um 20:21 schrieb Chris M. Thomasson:
>> On 9/21/2023 5:40 AM, Bonita Montero wrote:
>>> Am 21.09.2023 um 13:36 schrieb Richard Damon:
>>>
>>>> Why?
>>>
>>> Because the initialization might only take a microsecond or less
>>> and a yield is a full timeslice, on Linux and Windows usually one
>>> millisecond.
>>
>> An adaptive backoff can be a mixture of the PAUSE instruction aka x86,
>> and yield wrt the OS.
>
> Do you have a mental disorder ?
> We were discussing yielding.
>

An adaptive backoff is about yielding in interesting ways. Wow, you are
trying so hard to be a special kind of stubborn person right now. For
some reason, I would not trust you to create an adaptive backoff simply
because you seem to be radically confused about synchronization in general.

Re: Thread-safe initialization of static objects

<uelb75$fp8c$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 17:24:04 -0700
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <uelb75$fp8c$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me> <uegtd7$3dolc$1@dont-email.me>
<RW6PM.10144$hC28.451@fx01.iad> <uej5rh$3uji0$2@dont-email.me>
<0VePM.25326$fUu6.8952@fx47.iad> <uekjkd$bci8$4@dont-email.me>
<uekk4v$bl34$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 00:24:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="517388"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18DTTcY+m0PnSlET6plXmkodDSjbuDdcUg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:QQ443qaushacZN1nnn8KmlhyR7k=
In-Reply-To: <uekk4v$bl34$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 00:24 UTC

On 9/22/2023 10:50 AM, Bonita Montero wrote:
> Am 22.09.2023 um 19:41 schrieb Chris M. Thomasson:
>
>> Afaict, Bonita needs to study up on a great many things when it comes
>> to synchronization. Sometimes, I think Bonita is actually trolling on
>> purpose... Humm...
>
> The problem is not that I don't understand synchronization,

Hummm... I can read what you post here. There are a lot of issues.

> the problem
> is that I don't accept your objections where they don't fit the context.

Oh please. Man. Shit. You are the one that seems to enjoy to torching
scarecrows at the stake, and other types of straw men. Yikes!

I can read your posts, and I gather that you still have a LOT to learn.

Re: Thread-safe initialization of static objects

<uelce5$g184$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 17:44:52 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <uelce5$g184$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
<uekler$bqj8$1@dont-email.me> <IsoPM.20139$wO91.15127@fx39.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 00:44:53 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="525572"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19PSB3CFRJ/HLAOx9GfRlofANJTrlaUwBM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:vtmlX1NELT6S4Wd19bcVRuygwo8=
In-Reply-To: <IsoPM.20139$wO91.15127@fx39.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 00:44 UTC

On 9/22/2023 3:22 PM, Scott Lurndal wrote:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 22.09.2023 um 19:56 schrieb Scott Lurndal:
>>
>>> Why on earth would the run-time/dynamic loader use a C++ mutex
>>> instead of an implementation-defined primitive (e.g. pthread_once,
>>> pthread_mutex_t) which are easily statically initalized?
>>
>> pthread_mutex_init() can fail
>
> That is beside the point. The mutex can be statically initialized
> and the pthread_mutex_init call is unnecessary. You've been informed
> of this point at least a half dozen times in this thread alone.
>
> SYNOPSIS
> #include <pthread.h>
>
> int pthread_mutex_destroy(pthread_mutex_t *mutex);
> int pthread_mutex_init(pthread_mutex_t *restrict mutex,
> const pthread_mutexattr_t *restrict attr);
> pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
>

Bonita sure seems to be very set in its ways. Since this is not
something it knows about, it can tend to get fairly angry and lash out
with verbal assaults.

Re: Thread-safe initialization of static objects

<mDrPM.21297$EPT1.17110@fx02.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx02.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
<uds0qa$22qfj$1@dont-email.me> <udtg9s$2aqb5$1@dont-email.me>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<uegtd7$3dolc$1@dont-email.me> <RW6PM.10144$hC28.451@fx01.iad>
<uej5rh$3uji0$2@dont-email.me>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <uej5rh$3uji0$2@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 10
Message-ID: <mDrPM.21297$EPT1.17110@fx02.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sat, 23 Sep 2023 01:58:42 UTC
Date: Fri, 22 Sep 2023 21:58:31 -0400
X-Received-Bytes: 2024
 by: Pavel - Sat, 23 Sep 2023 01:58 UTC

Bonita Montero wrote:
> Am 22.09.2023 um 04:25 schrieb Pavel:
>
>> What are you trying to prove? ..
>
> THat mem is initiallly zero, although this isn't guarenteed for
> static fundamental types.
>
Nice try. Some memory is initialized to zero, some is not. None of this
proves that C++ standard spec of static initialization should be changed.

Re: Thread-safe initialization of static objects

<%SrPM.146243$GHI6.55586@fx17.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!newsfeed.endofthelinebbs.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx17.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me> <DS6PM.104552$GHI6.65122@fx17.iad>
<ueiuar$3tima$5@dont-email.me>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <ueiuar$3tima$5@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 24
Message-ID: <%SrPM.146243$GHI6.55586@fx17.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sat, 23 Sep 2023 02:15:23 UTC
Date: Fri, 22 Sep 2023 22:15:23 -0400
X-Received-Bytes: 2640
 by: Pavel - Sat, 23 Sep 2023 02:15 UTC

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

POSIX synchronization primitives are not created, they are initialized.
Incidentally, the easiest way to initialize mutex and pthread_once_t is
to constant-initialize them to what is defined on Linux as zero memory.
This cannot fail for static mutex or pthread_once_t.

How can this constant initialization of INIT_ONCE primitive on Windows fail?
static INIT_ONCE io = INIT_ONCE_STATIC_INIT;

How can a call to InitOnceExecuteOnce on propertly initialized INIT_ONCE
object fail?

Right, they cannot. So stop making false claims.

Re: Thread-safe initialization of static objects

<f_rPM.17178$UHH3.1746@fx45.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.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> <aJINM.23275$H8td.10140@fx10.iad>
<ue8lv5$q25a$3@dont-email.me> <th7PM.6493$wGe2.6301@fx03.iad>
<uej5tu$3uji0$3@dont-email.me>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <uej5tu$3uji0$3@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 18
Message-ID: <f_rPM.17178$UHH3.1746@fx45.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sat, 23 Sep 2023 02:23:07 UTC
Date: Fri, 22 Sep 2023 22:23:07 -0400
X-Received-Bytes: 2535
 by: Pavel - Sat, 23 Sep 2023 02:23 UTC

Bonita Montero wrote:
> Am 22.09.2023 um 04:50 schrieb Pavel:
>
>> A "deferred" initialization of a static sync primitive used to sync
>> static initialization of a C++ object is not only unnecessary
>> (constant initialization is enough) but also would be useless if used.
>> Because how would you correctly synchronize this "deferred"
>> initialization itself if the initialization of the static object is
>> requested concurrently from 2 threads. You should stop invent and talk
>> nonsense.
>
> A lock may be never contended or contended very lately, so that
> delayed allocation of the kernel semaphore may make sense.
>
No, it cannot make sense. A "deferred" initialization of a static
synchronization primitive is itself not thread-safe; hence it cannot be
used to initialize a static C++ object in a thread-safe manner. Plain
and simple.

Re: Thread-safe initialization of static objects

<VnsPM.122464$Hih7.52058@fx11.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!newsfeed.hasname.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.iad.POSTED!not-for-mail
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <udn883$135tl$1@dont-email.me>
<udnqhc$160ia$3@dont-email.me> <udoico$1d0tr$1@dont-email.me>
<udotj5$1e8do$2@dont-email.me> <udpbun$1gf8c$1@dont-email.me>
<udqatg$1mar3$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me>
From: pauldont...@removeyourself.dontspam.yahoo (Pavel)
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101
Firefox/91.0 SeaMonkey/2.53.17
MIME-Version: 1.0
In-Reply-To: <uej631$3uji0$4@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 27
Message-ID: <VnsPM.122464$Hih7.52058@fx11.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Sat, 23 Sep 2023 02:50:29 UTC
Date: Fri, 22 Sep 2023 22:50:29 -0400
X-Received-Bytes: 2871
 by: Pavel - Sat, 23 Sep 2023 02:50 UTC

Bonita Montero wrote:
> Am 22.09.2023 um 04:58 schrieb Pavel:
>
>> It **is** the job of the standard authors to assume what elementary
>> operations can and what cannot fail and build their specs upon that.
>
> Mutex synchronization can fail at least in C++
for some mutex it may fail, for some not. C++ standard never says that
std::mutex can fail. This is irrelevant because C++ once_flag
initialization cannot fail and the standard specifically advises using
other synchronization to ensure that mutex objects are initialized and
visible to other threads

> because of delayed
> initialization
"delayed" or "deferred" initialization of synchronization primitives
that can be used to initialize static C++ object is entirely your
fantasy. It cannot be used for this purpose, period.

> since the constructor itself of mutex is noexcept.
irrelevant. std::once_flag constructor is noexcept and once_flag
initialization cannot fail.

> It's the same with whatever is used for static initializatiionsince
> the mutex-ish data structure is created when there's contention.
Wrong. std::once_flag constructor is noexcept and once_flag
initialization cannot fail.

Re: Thread-safe initialization of static objects

<uelllt$l6g0$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 20:22:37 -0700
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <uelllt$l6g0$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
<uds0qa$22qfj$1@dont-email.me> <udtg9s$2aqb5$1@dont-email.me>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<z1MOM.13123$TwR4.1703@fx46.iad> <uegt3a$3dj0r$4@dont-email.me>
<DS6PM.104552$GHI6.65122@fx17.iad> <ueiuar$3tima$5@dont-email.me>
<%SrPM.146243$GHI6.55586@fx17.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 03:22:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="694784"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19d3sE1l5/BZ5iFoVWgTm5Ae02VUsM5Ku8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:WQ2QJBk+8HnoYm/hMCdsOCFnOk8=
In-Reply-To: <%SrPM.146243$GHI6.55586@fx17.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 03:22 UTC

On 9/22/2023 7:15 PM, Pavel wrote:
> Bonita Montero wrote:
>> Am 22.09.2023 um 04:21 schrieb Pavel:
>>
>>> How does the above prove your wrong point that initialization of
>>> static synchronization primitives always may fail? ...
>>
>> The mutex is created along with the static object from zeroed memory
>> whene there's contention. At least this may fail. And with Windows
>> the synchronization may also fail.
> Neither fails if implemented propertly.
>
> POSIX synchronization primitives are not created, they are initialized.
> Incidentally, the easiest way to initialize mutex and pthread_once_t is
> to constant-initialize them to what is defined on Linux as zero memory.
> This cannot fail for static mutex or pthread_once_t.
>
> How can this constant initialization of INIT_ONCE primitive on Windows
> fail?
> static INIT_ONCE io = INIT_ONCE_STATIC_INIT;
>
> How can a call to InitOnceExecuteOnce on propertly initialized INIT_ONCE
> object fail?
>
> Right, they cannot. So stop making false claims.
>

Ding! You are correct.

Re: Thread-safe initialization of static objects

<uelm9n$l6g0$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 20:33:10 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <uelm9n$l6g0$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udqbg3$1mdv6$1@dont-email.me>
<udqq8u$1p3q6$1@dont-email.me> <uds0qa$22qfj$1@dont-email.me>
<udtg9s$2aqb5$1@dont-email.me> <uduimg$2imqi$1@dont-email.me>
<FUEMM.7469$ZkX3.6739@fx09.iad> <ue3bhh$3l4s1$1@dont-email.me>
<ue3nga$3ms5s$1@dont-email.me> <eohNM.4832$3lL1.1360@fx47.iad>
<ue4cqe$3rjfr$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <ue4t6i$3um57$1@dont-email.me>
<ue5sp2$7ms9$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <z1MOM.13123$TwR4.1703@fx46.iad>
<uegt3a$3dj0r$4@dont-email.me> <uegtd7$3dolc$1@dont-email.me>
<RW6PM.10144$hC28.451@fx01.iad> <uej5rh$3uji0$2@dont-email.me>
<mDrPM.21297$EPT1.17110@fx02.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Sep 2023 03:33:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="694784"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Bbasc6OPfkmrMwQ0r3u262JZXAZGqif4="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:fIpKaL4J8dxCJ3TXX52JzXxkvK4=
In-Reply-To: <mDrPM.21297$EPT1.17110@fx02.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 03:33 UTC

On 9/22/2023 6:58 PM, Pavel wrote:
> Bonita Montero wrote:
>> Am 22.09.2023 um 04:25 schrieb Pavel:
>>
>>> What are you trying to prove? ..
>>
>> THat mem is initiallly zero, although this isn't guarenteed for
>> static fundamental types.
>>
> Nice try. Some memory is initialized to zero, some is not. None of this
> proves that C++ standard spec of static initialization should be changed.

Afaict, Bonita is not stupid at all. That's the odd ball part. Humm...

Re: Thread-safe initialization of static objects

<uelq44$lo9j$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sat, 23 Sep 2023 06:38:31 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uelq44$lo9j$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad> <uecac1$2cj86$1@dont-email.me>
<iwpOM.265$Sn81.181@fx08.iad> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<ueggh5$3bq3f$1@dont-email.me> <uegsdo$3dj0r$1@dont-email.me>
<uei1g6$3l13h$2@dont-email.me> <ueiu42$3tima$1@dont-email.me>
<eE7PM.16350$3vM.3605@fx37.iad> <uej5q1$3uji0$1@dont-email.me>
<gWePM.25327$fUu6.21270@fx47.iad> <uek0g4$7fl1$1@dont-email.me>
<jBoPM.25452$fUu6.14009@fx47.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 04:38:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ef0c2489862b938887f0220cc4fc605";
logging-data="713011"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ShwmYqtAH1Nbx/ICl/GrR1CIMISHAmF4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:KGLl6vNW7d0HrDLHPK0LEzKctHw=
In-Reply-To: <jBoPM.25452$fUu6.14009@fx47.iad>
Content-Language: de-DE
 by: Bonita Montero - Sat, 23 Sep 2023 04:38 UTC

Am 23.09.2023 um 00:31 schrieb Richard Damon:

> The fact that you are too stupid to understand how these things actually
> work and give performant results doesn't mean they don't do it. The fact
> that they do shows your ignorance.

Yielding at this place and spin-locking in userspace is unprofessional.

Re: Thread-safe initialization of static objects

<uelq9h$lo9j$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sat, 23 Sep 2023 06:41:24 +0200
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <uelq9h$lo9j$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
<uekler$bqj8$1@dont-email.me> <20230922111441.730@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 04:41:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ef0c2489862b938887f0220cc4fc605";
logging-data="713011"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18wCg7QuQUsQfy28WSEI7Fgq4fAG9yBLhs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:+xPMLRCbehMQzdgAceFJdxE6brM=
In-Reply-To: <20230922111441.730@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Sat, 23 Sep 2023 04:41 UTC

Am 22.09.2023 um 20:38 schrieb Kaz Kylheku:

> POSIX provides a PTHREAD_MUTEX_INITIALIZER which lets you do just this:
> pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;

Ok, then Posix threads also can do delayed initialization of the
kernel part for the slow path. And I see that InitializeCriticalSection
doesn't fail but EnterCriticalSection can, i.e. there's also delayed
initialization.

Re: Thread-safe initialization of static objects

<uelqb1$lo9j$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sat, 23 Sep 2023 06:42:12 +0200
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <uelqb1$lo9j$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
<uekler$bqj8$1@dont-email.me> <IsoPM.20139$wO91.15127@fx39.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 04:42:09 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ef0c2489862b938887f0220cc4fc605";
logging-data="713011"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195L3roj5oieUWU1dnV2DbMj/wtVDA5JxA="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:px+kz5a0s321AwpcmSWgS8nucxM=
In-Reply-To: <IsoPM.20139$wO91.15127@fx39.iad>
Content-Language: de-DE
 by: Bonita Montero - Sat, 23 Sep 2023 04:42 UTC

Am 23.09.2023 um 00:22 schrieb Scott Lurndal:

> That is beside the point. The mutex can be statically initialized
> ...

This depends on the program which uses the mutex.

Re: Thread-safe initialization of static objects

<uelqeq$lo9j$4@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sat, 23 Sep 2023 06:44:13 +0200
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <uelqeq$lo9j$4@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udnqhc$160ia$3@dont-email.me>
<udoico$1d0tr$1@dont-email.me> <udotj5$1e8do$2@dont-email.me>
<udpbun$1gf8c$1@dont-email.me> <udqatg$1mar3$1@dont-email.me>
<udqbg3$1mdv6$1@dont-email.me> <udqq8u$1p3q6$1@dont-email.me>
<uds0qa$22qfj$1@dont-email.me> <udtg9s$2aqb5$1@dont-email.me>
<uduimg$2imqi$1@dont-email.me> <FUEMM.7469$ZkX3.6739@fx09.iad>
<ue3bhh$3l4s1$1@dont-email.me> <ue3nga$3ms5s$1@dont-email.me>
<eohNM.4832$3lL1.1360@fx47.iad> <ue4cqe$3rjfr$1@dont-email.me>
<LwlNM.50924$QShe.20423@fx11.iad> <ue4p5v$3truj$1@dont-email.me>
<EjoNM.17221$DXgc.9861@fx36.iad> <ue5tfc$7pns$1@dont-email.me>
<zPGNM.14021$BMnd.11871@fx04.iad> <ue7f6g$frod$2@dont-email.me>
<LWINM.13017$ZkX3.12109@fx09.iad> <ue8mn0$q534$4@dont-email.me>
<uY5OM.30730$Yxl8.13078@fx14.iad> <ueb3sb$2638l$6@dont-email.me>
<ZjMOM.9398$EIy4.4982@fx48.iad> <uegsia$3dj0r$2@dont-email.me>
<fp7PM.104556$GHI6.80009@fx17.iad> <uej631$3uji0$4@dont-email.me>
<VnsPM.122464$Hih7.52058@fx11.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 04:44:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ef0c2489862b938887f0220cc4fc605";
logging-data="713011"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yzv5dY3aEYX2l49dTmUlB+x1LlMSIz2M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:wbvRLNHcFPMCrHORb+QaiIEoggk=
Content-Language: de-DE
In-Reply-To: <VnsPM.122464$Hih7.52058@fx11.iad>
 by: Bonita Montero - Sat, 23 Sep 2023 04:44 UTC

Am 23.09.2023 um 04:50 schrieb Pavel:

> for some mutex it may fail, for some not. C++ standard never says that
> std::mutex can fail. ...

std::mutex::lock() can throw a system_error.

> "delayed" or "deferred" initialization of synchronization primitives
> that can be used to initialize static C++ object is entirely your
> fantasy. It cannot be used for this purpose, period.

The mutex' constructor doesn't throw, so there must be delayed
initialization. But as we've seen recently pthread Mutexes also
allow delayed initialization of the slow path and Win32 always
does the same.

Re: Thread-safe initialization of static objects

<uelure$m9hj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 22:59:09 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <uelure$m9hj$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
<uekler$bqj8$1@dont-email.me> <20230922111441.730@kylheku.com>
<uelq9h$lo9j$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Sep 2023 05:59:10 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="730675"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+qHyy1aV/CF0w948prjmIF+LAPUECobDU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:4lzGgP2E+P/IRUATDP8Gm7bui6U=
In-Reply-To: <uelq9h$lo9j$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 05:59 UTC

On 9/22/2023 9:41 PM, Bonita Montero wrote:
> Am 22.09.2023 um 20:38 schrieb Kaz Kylheku:
>
>> POSIX provides a PTHREAD_MUTEX_INITIALIZER which lets you do just this:
>>    pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
>
> Ok, then Posix threads also can do delayed initialization of the
> kernel  part for the slow path. And I see that InitializeCriticalSection
> doesn't fail but EnterCriticalSection can, i.e. there's also delayed
> initialization.
>

POSIX is a standard, EnterCriticalSection is a mutex for windows. You
need to check this out, wrt windows:

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

POSIX needs to work with the compiler and vise versa, like a system, or
else the contract is broken. A system that wants to allow itself to
adhere to POSIX must make sure it works within the POSIX std.

Re: Thread-safe initialization of static objects

<uelvjm$ma8c$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 23:12:06 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uelvjm$ma8c$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue7gb8$fumm$3@dont-email.me>
<ue7gkn$g3o5$1@dont-email.me> <20230917121015.206@kylheku.com>
<ue7k2n$gmqv$1@dont-email.me> <20230917123203.524@kylheku.com>
<ue8lst$q25a$2@dont-email.me> <20230918101705.91@kylheku.com>
<uea1rj$1saml$1@dont-email.me> <hK5OM.30729$Yxl8.9621@fx14.iad>
<ueb3f7$2638l$2@dont-email.me> <ueb9vm$271en$3@dont-email.me>
<uebn4f$293m3$2@dont-email.me> <1GhOM.7399$H0Ge.6907@fx05.iad>
<uecac1$2cj86$1@dont-email.me> <iwpOM.265$Sn81.181@fx08.iad>
<uedp93$2orvq$2@dont-email.me> <k4BOM.2058$TwR4.78@fx46.iad>
<ueeret$2upib$1@dont-email.me> <JCKOM.83797$2ph4.24937@fx14.iad>
<uege3r$3bfsj$2@dont-email.me> <ueggh5$3bq3f$1@dont-email.me>
<uegsdo$3dj0r$1@dont-email.me> <uei1g6$3l13h$2@dont-email.me>
<ueiu42$3tima$1@dont-email.me> <eE7PM.16350$3vM.3605@fx37.iad>
<uej5q1$3uji0$1@dont-email.me> <gWePM.25327$fUu6.21270@fx47.iad>
<uek0g4$7fl1$1@dont-email.me> <jBoPM.25452$fUu6.14009@fx47.iad>
<uelq44$lo9j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 06:12:06 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="731404"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1847lxfCJugCgI7eww1XwTiCr4VMl3XQ3w="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:lSxn19CbWp91Bi3ToF8AG53kWP4=
In-Reply-To: <uelq44$lo9j$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 06:12 UTC

On 9/22/2023 9:38 PM, Bonita Montero wrote:
> Am 23.09.2023 um 00:31 schrieb Richard Damon:
>
>> The fact that you are too stupid to understand how these things
>> actually work and give performant results doesn't mean they don't do
>> it. The fact that they do shows your ignorance.
>
> Yielding at this place and spin-locking in userspace is unprofessional.
>

It's "unprofessional" in this place to, basically, claim that you know
what you are doing, when you really do not?

Re: Thread-safe initialization of static objects

<uem04n$ma8c$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Fri, 22 Sep 2023 23:21:11 -0700
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uem04n$ma8c$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <ue4p5v$3truj$1@dont-email.me>
<ue4t6i$3um57$1@dont-email.me> <ue5sp2$7ms9$1@dont-email.me>
<ue7gb8$fumm$3@dont-email.me> <ue7gkn$g3o5$1@dont-email.me>
<20230917121015.206@kylheku.com> <ue7k2n$gmqv$1@dont-email.me>
<20230917123203.524@kylheku.com> <ue8lst$q25a$2@dont-email.me>
<20230918101705.91@kylheku.com> <uea1rj$1saml$1@dont-email.me>
<hK5OM.30729$Yxl8.9621@fx14.iad> <ueb3f7$2638l$2@dont-email.me>
<ueb9vm$271en$3@dont-email.me> <uebn4f$293m3$2@dont-email.me>
<1GhOM.7399$H0Ge.6907@fx05.iad> <uecac1$2cj86$1@dont-email.me>
<iwpOM.265$Sn81.181@fx08.iad> <uedp93$2orvq$2@dont-email.me>
<k4BOM.2058$TwR4.78@fx46.iad> <ueeret$2upib$1@dont-email.me>
<JCKOM.83797$2ph4.24937@fx14.iad> <uege3r$3bfsj$2@dont-email.me>
<DUVOM.87557$noZ7.33800@fx13.iad> <uehdjj$3h8me$3@dont-email.me>
<uei1je$3l13h$3@dont-email.me> <20230921114029.796@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Sep 2023 06:21:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="68142c7755e948501d20eaef3fa69779";
logging-data="731404"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18naIVdyB3V8YFU7Z1CFNmyvGQ2c+PwOXo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.1
Cancel-Lock: sha1:VyaTlJlK22AxnCNgcRQBfhxhKiI=
In-Reply-To: <20230921114029.796@kylheku.com>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Sep 2023 06:21 UTC

On 9/21/2023 11:42 AM, Kaz Kylheku wrote:
> On 2023-09-21, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
>> On 9/21/2023 5:40 AM, Bonita Montero wrote:
>>> Am 21.09.2023 um 13:36 schrieb Richard Damon:
>>>
>>>> Why?
>>>
>>> Because the initialization might only take a microsecond or less
>>> and a yield is a full timeslice, on Linux and Windows usually one
>>> millisecond.
>>
>> An adaptive backoff can be a mixture of the PAUSE instruction aka x86,
>> and yield wrt the OS.
>
> Ideally there shouldn't be a difference? In user mode execution, PAUSE
> should be a privileged instruction. User space must not pause the
> machine until an interrupt occurs. The privileged instruction will trap
> to the kernel, where it becomes equivalent to a yield().
>
> In the kernel, the lowest-priority idle task might execute that
> instruction in a loop: the real one, not the trap.
>
> When the scheduler determines there is truly nothing to do then it is
> legitimate to dispatch an idle task which suspends the processor until
> an external event.
>

I have seen experimental adaptive backoff schemes on several platforms,
windows one rings a bell, it used used PAUSE, SwitchToThread, Sleep(0),
and even Sleep(1), before it waited in the kernel. It kept statistics,
and tried to see that if the adaptive backoff can be used to increase
performance and reduce the number of times it waited in the kernel. For
certain workloads, it worked out pretty good, for others not so much...

Re: Thread-safe initialization of static objects

<uem0t7$miuj$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sat, 23 Sep 2023 08:34:17 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <uem0t7$miuj$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
<uekler$bqj8$1@dont-email.me> <20230922111441.730@kylheku.com>
<uelq9h$lo9j$2@dont-email.me> <uelure$m9hj$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Sep 2023 06:34:15 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ef0c2489862b938887f0220cc4fc605";
logging-data="740307"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/PrOHqe2Ng26iLF+Rc0jGuqvl+c8YKsNo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Z/bcJ/8ITykoDwKHzZu9qNeD2I0=
Content-Language: de-DE
In-Reply-To: <uelure$m9hj$1@dont-email.me>
 by: Bonita Montero - Sat, 23 Sep 2023 06:34 UTC

Am 23.09.2023 um 07:59 schrieb Chris M. Thomasson:
> On 9/22/2023 9:41 PM, Bonita Montero wrote:
>> Am 22.09.2023 um 20:38 schrieb Kaz Kylheku:
>>
>>> POSIX provides a PTHREAD_MUTEX_INITIALIZER which lets you do just this:
>>>    pthread_mutex_t mtx = PTHREAD_MUTEX_INITIALIZER;
>>
>> Ok, then Posix threads also can do delayed initialization of the
>> kernel  part for the slow path. And I see that InitializeCriticalSection
>> doesn't fail but EnterCriticalSection can, i.e. there's also delayed
>> initialization.
>>
>
> POSIX is a standard, EnterCriticalSection is a mutex for windows.
> You need to check this out, wrt windows:

I'm talking of common properties of both.

>
> https://learn.microsoft.com/en-us/windows/win32/api/synchapi/nf-synchapi-waitonaddress
>
> POSIX needs to work with the compiler and vise versa, like a system, or
> else the contract is broken. A system that wants to allow itself to
> adhere to POSIX must make sure it works within the POSIX std.

Re: Thread-safe initialization of static objects

<uem0vd$miuj$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sat, 23 Sep 2023 08:35:27 +0200
Organization: A noiseless patient Spider
Lines: 142
Message-ID: <uem0vd$miuj$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <LwlNM.50924$QShe.20423@fx11.iad>
<ue4p5v$3truj$1@dont-email.me> <EjoNM.17221$DXgc.9861@fx36.iad>
<ue5tfc$7pns$1@dont-email.me> <zPGNM.14021$BMnd.11871@fx04.iad>
<ue7f6g$frod$2@dont-email.me> <LWINM.13017$ZkX3.12109@fx09.iad>
<ue8mn0$q534$4@dont-email.me> <uY5OM.30730$Yxl8.13078@fx14.iad>
<ueb3sb$2638l$6@dont-email.me> <ZjMOM.9398$EIy4.4982@fx48.iad>
<uegsia$3dj0r$2@dont-email.me> <fp7PM.104556$GHI6.80009@fx17.iad>
<uej631$3uji0$4@dont-email.me> <mzkPM.16155$ugs.3977@fx36.iad>
<uekler$bqj8$1@dont-email.me> <20230922111441.730@kylheku.com>
<uelq9h$lo9j$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 23 Sep 2023 06:35:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2ef0c2489862b938887f0220cc4fc605";
logging-data="740307"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19CPXHBpc+Fvt160D6EnhUI8d8ca+9fbWc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:IFsmqN7xvjPm9tUGV6ya3L2g4eU=
In-Reply-To: <uelq9h$lo9j$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 23 Sep 2023 06:35 UTC

Am 23.09.2023 um 06:41 schrieb Bonita Montero:

> Ok, then Posix threads also can do delayed initialization of the
> kernel  part for the slow path. And I see that InitializeCriticalSection
> doesn't fail but EnterCriticalSection can, i.e. there's also delayed
> initialization.

This is how a mutex whose constructor is noexcept works.
The code demonstrates the delayed initialization of the slow path:

#if defined(_WIN32)
#include <Windows.h>
#elif defined(__unix__)
#include <fcntl.h>
#include <semaphore.h>
#endif
#include <iostream>
#include <atomic>
#include <cassert>
#include <system_error>
#include <memory>

using namespace std;

struct DelayedMutex
{ DelayedMutex() noexcept;
~DelayedMutex();
void lock();
void unlock();
private:
#if defined(_WIN32)
HANDLE getSem();
#elif defined(__unix__)
sem_t *getSem();
#endif
atomic<unsigned> m_lockCounter;
#if defined(_WIN32)
static_assert(atomic<HANDLE>::is_always_lock_free, "atomic<HANDLE> must
be lock-free");
atomic<HANDLE> m_hSem;
#elif defined(__unix__)
atomic<sem_t *> m_sem;
#endif
};

DelayedMutex::DelayedMutex() noexcept :
m_lockCounter( 0 ),
#if defined(_WIN32)
m_hSem( NULL )
#elif defined(__unix__)
m_sem( nullptr )
#endif
{ }

DelayedMutex::~DelayedMutex()
{ assert(!m_lockCounter.load( memory_order_relaxed ));
#if defined(_WIN32)
HANDLE hSem = m_hSem.load( memory_order_relaxed );
if( hSem )
CloseHandle( hSem );
#elif defined(__unix__)
sem_t *sem = m_sem.load( memory_order_relaxed );
if( sem )
sem_destroy( sem ),
delete sem;
#endif
}

void DelayedMutex::lock()
{ unsigned before = m_lockCounter.fetch_add( 1, memory_order_acquire );
assert(before != -1);
if( !before ) [[likely]]
return;
#if defined(_WIN32)
if( WaitForSingleObject( getSem(), INFINITE ) != WAIT_OBJECT_0 )
[[unlikely]]
#elif defined(__unix__)
if( sem_wait( getSem() ) ) [[unlikely]]
#endif
terminate();
}

void DelayedMutex::unlock()
{ unsigned before = m_lockCounter.fetch_sub( 1, memory_order_acquire );
assert(before >= 1);
if( before == 1 ) [[likely]]
return;
#if defined(_WIN32)
if( !SetEvent( getSem() ) )[[unlikely]]
#elif defined(__unix__)
if( sem_post( getSem() ) ) [[unlikely]]
#endif
terminate();
}

#if defined(_WIN32)
HANDLE DelayedMutex::getSem()
{ HANDLE hSem = m_hSem.load( memory_order_relaxed );
if( hSem ) [[likely]]
return hSem;
hSem = CreateEventA( nullptr, FALSE, FALSE, nullptr );
if( !hSem ) [[unlikely]]
throw system_error( GetLastError(), system_category(), "kernel
semaphore creation failed" );
HANDLE hSemExpected = NULL;
if( !m_hSem.compare_exchange_weak( hSemExpected, hSem,
memory_order_relaxed, memory_order_relaxed ) ) [[unlikely]]
CloseHandle( hSem ),
hSem = hSemExpected;
return hSem;
} #elif defined(__unix__)
sem_t *DelayedMutex::getSem()
{ sem_t *sem = m_sem.load( memory_order_relaxed );
if( sem ) [[likely]]
return sem;
unique_ptr<sem_t> newSem( make_unique<sem_t>() );
if( sem_init( &*newSem, 0, 0 ) ) [[unlikely]]
throw system_error( errno, system_category(), "kernel semaphore
creation failed" );
sem_t *semExpected = nullptr;
if( m_sem.compare_exchange_weak( semExpected, &*newSem,
memory_order_relaxed, memory_order_relaxed ) ) [[likely]]
sem = &*newSem,
newSem.release();
else
sem_destroy( &*newSem ),
sem = semExpected;
return sem;
} #endif

int main()
{ }


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

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor