Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Debian is like Suse with yast turned off, just better. :) -- Goswin Brederlow


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

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

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

<udigh5$6amo$4@dont-email.me>

  copy mid

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

  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: Sat, 9 Sep 2023 12:20:04 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <udigh5$6amo$4@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 19:20:05 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a3b350a6648114514a7c92794ed6367";
logging-data="207576"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RWE+yicuWzBIUC9CkeCYWGYtlLTz5t6M="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:ilq+uJemD3Du+YnXV5xTfWbUiaU=
In-Reply-To: <udigbv$6ddc$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 9 Sep 2023 19:20 UTC

On 9/9/2023 12:17 PM, Bonita Montero wrote:
> Am 09.09.2023 um 20:49 schrieb Chris M. Thomasson:
>
>> Huh? pthread_once totally applies here. Windows has futex like abilities.
>
> It doesn't matter what Posix or Win32 says.

Are you sure about that?

> The standard should
> honour that static initialization might fail because of creating
> a synchronization primitive or synchronizing on them. The standard
> shoudln't require that this never fails.
>

Might fail? For what reasons?

Re: Thread-safe initialization of static objects

<udigjh$6amo$5@dont-email.me>

  copy mid

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

  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: Sat, 9 Sep 2023 12:21:20 -0700
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <udigjh$6amo$5@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 19:21:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a3b350a6648114514a7c92794ed6367";
logging-data="207576"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yN7RsZASxijHMObVab8KDNStlYfIxHuw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:igaMX+A4NIC6nHwgxVGC+7fpO1E=
In-Reply-To: <udigbv$6ddc$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 9 Sep 2023 19:21 UTC

On 9/9/2023 12:17 PM, Bonita Montero wrote:
> Am 09.09.2023 um 20:49 schrieb Chris M. Thomasson:
>
>> Huh? pthread_once totally applies here. Windows has futex like abilities.
>
> It doesn't matter what Posix or Win32 says. The standard should
> honour that static initialization might fail because of creating
> a synchronization primitive or synchronizing on them. The standard
> shoudln't require that this never fails.
>

Are you talking about a user object that is statically initialized
failing, throwing an exception, calling exit, or something?

Re: Thread-safe initialization of static objects

<udii8a$6ih8$1@dont-email.me>

  copy mid

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

  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: Sat, 9 Sep 2023 12:49:29 -0700
Organization: A noiseless patient Spider
Lines: 106
Message-ID: <udii8a$6ih8$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udc6n0$2uo4t$1@dont-email.me>
<udghd4$3p30t$1@dont-email.me> <udgiom$3p7e1$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 9 Sep 2023 19:49:30 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a3b350a6648114514a7c92794ed6367";
logging-data="215592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/smYxVa0MCADXD+EzQt41gPALpNuGvtGw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:ZnDkf6bUHiXwvvb8crrGtvFKSas=
In-Reply-To: <udgiom$3p7e1$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 9 Sep 2023 19:49 UTC

On 9/8/2023 6:45 PM, Chris M. Thomasson wrote:
> On 9/8/2023 6:22 PM, Chris M. Thomasson wrote:
>> On 9/7/2023 2:55 AM, Paavo Helde wrote:
>>> 06.09.2023 21:15 Bonita Montero kirjutas:
>>>> With C++11 static local or global data is initialized thread-safe.
>>>> This is  usually done with double checked locking (DCL). DCL needs
>>>> a flag along with the static data which shows if the data already
>>>> is initialized and a mutex which guards the initalization.
>>>> I assumed that an implementation simply would use a central mutex
>>>> for all static data objects since it includes a kernel semaphore,
>>>> which is a costly resource.
>>>> To find out if this is true I wrote the below application:
>>> [...]
>>>> SleepAtInitialize<IObj> is instantiated only once per thread with this
>>>> code. So the threads don't share a central object. If there would be
>>>> a central mutex used the above code would run for about 10s. But the
>>>> code does run about one second,
>>>
>>> There is a note in the standard: "[Note: This definition permits
>>> initialization of a sequence of ordered variables concurrently with
>>> another sequence. —end note]"
>>>
>>>   i.e. there are indivual mutexes per
>>>> each instantiation of SleepAtInitiaize<>. I.e. the creation of the
>>>> mutex is also done with the static initialization. The mutex
>>>> constructor
>>>> is noexcept, so mutexes always must be created on their first use. This
>>>> is done while the DCL-locked creation of the static object. So at last
>>>> static initialization should be declared to throw a system_errror. But
>>>> I can't find anything about that in the standard.
>>>
>>> Some debugging with VS2022 seems to indicate it is using a Windows
>>> critical section for thread-safe statics initialization.
>>> EnterCriticalSection() does not return any error code and of course
>>> does not throw any C++ exceptions either, so it is supposed to never
>>> fail.
>>
>> If it does fail, then some rather radical shit has hit the fan.
>>
>>
>>>
>>> Yes, it's true it can throw a Windows structured exception
>>> EXCEPTION_POSSIBLE_DEADLOCK (after 30 days by default). But this
>>> would be considered as a fault in the program. This is what the C++
>>> standard says about deadlocks (again a footnote):
>>>
>>> "The implementation must not introduce any deadlock around execution
>>> of the initializer. Deadlocks might still be caused by the program
>>> logic; the implementation need only avoid deadlocks due to its own
>>> synchronization operations."
>>>
>>> So I gather that in case the thread-safe static init synchronization
>>> fails, there must be a bug in the implementation. No C++ exceptions
>>> would be thrown anyway.
>>
>> Right. The implementation must get it right using fine grain locking,
>> amortized table locking, or some other means. The compiler and POSIX
>> worth together like a system. Iirc, I saw another way that was
>> lock-free, but allowed a thread to create an object, then might have
>> to delete it because it was not the first one to be installed in the
>> sense of being visible to other threads. This was decades ago, iirc it
>> used CAS. No mutex.
>
> Iirc it was something like:
>
> static foo* g_foo = nullptr;
>
> foo* l_foo = g_foo; // atomic load
>
> if (! l_foo)
> {
>   foo* t_foo = new foo;
>   foo* cmp = nullptr;
>
>   // CAS would update the comparand on failure.
>   // Take special note of that...
>
>   // mb release
>
>   if (! CAS(&g_foo, &cmp, t_foo)) // atomic rmw
>   {
>     // failed!!! well, shit happens!
>     delete t_foo;
>     t_foo = cmp;
>     // mb acquire
>   }

// God damn it! There is a bug right here.
// I forgot to set l_foo to t_foo.

SHIT!

l_foo = t_foo;

God damn it!

> }
>
> else
> {
>   // mb acquire
> }
>
> l_foo->bar();

Re: Thread-safe initialization of static objects

<udiifa$6mlq$1@dont-email.me>

  copy mid

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

  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: Sat, 9 Sep 2023 12:53:13 -0700
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <udiifa$6mlq$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <udc6n0$2uo4t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 19:53:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a3b350a6648114514a7c92794ed6367";
logging-data="219834"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184MDYWzcLL5QCRdwGrrgpSpIa4KyuJBjM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:d7yl5zosqyTerx+71Jugts8jcrE=
Content-Language: en-US
In-Reply-To: <udc6n0$2uo4t$1@dont-email.me>
 by: Chris M. Thomasson - Sat, 9 Sep 2023 19:53 UTC

On 9/7/2023 2:55 AM, Paavo Helde wrote:
[...]

I should create a new thread for this, but this is my corrected
pseudo-code. I forgot to set l_foo to t_foo in my previous code. So
sorry about that nonsense.

static foo* g_foo = nullptr;

foo* l_foo = g_foo; // atomic load

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

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

// mb release

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

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

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

else
{ // mb acquire
}

l_foo->bar();

Re: Thread-safe initialization of static objects

<udiiim$6ngs$1@dont-email.me>

  copy mid

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

  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, 9 Sep 2023 21:55:02 +0200
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <udiiim$6ngs$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <udigh5$6amo$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 19:55:02 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="40fc38809065ec861f987de259190c0a";
logging-data="220700"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dnKrpTCPgCD4orDNtjVAV1naoE+EtFyY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:8tW0D7tZTyuhwuSXPayksjRtX6g=
In-Reply-To: <udigh5$6amo$4@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 9 Sep 2023 19:55 UTC

Am 09.09.2023 um 21:20 schrieb Chris M. Thomasson:

>> It doesn't matter what Posix or Win32 says.

> Are you sure about that?

The standard is operating system agnostic.

> Might fail? For what reasons?

F.e. because there's no more non-pageable memory for a semaphore.

Re: Thread-safe initialization of static objects

<udiiqu$6ih8$2@dont-email.me>

  copy mid

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

  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: Sat, 9 Sep 2023 12:59:25 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <udiiqu$6ih8$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <udigh5$6amo$4@dont-email.me>
<udiiim$6ngs$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 19:59:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a3b350a6648114514a7c92794ed6367";
logging-data="215592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19MUNoTT4in/ZCg5FN0da95l5eKYB/VSlE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:RRteLnaAleS6cyDy3XUUs6FarOk=
Content-Language: en-US
In-Reply-To: <udiiim$6ngs$1@dont-email.me>
 by: Chris M. Thomasson - Sat, 9 Sep 2023 19:59 UTC

On 9/9/2023 12:55 PM, Bonita Montero wrote:
> Am 09.09.2023 um 21:20 schrieb Chris M. Thomasson:
>
>>> It doesn't matter what Posix or Win32 says.
>
>> Are you sure about that?
>
> The standard is operating system agnostic.
>
>> Might fail? For what reasons?
>
> F.e. because there's no more non-pageable memory for a semaphore.
>

An address based hash into a table based approach works by creating
everything up front. If this fails, then the user program logic is not
even executed at all.

Re: Thread-safe initialization of static objects

<udiisq$6ih8$3@dont-email.me>

  copy mid

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

  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: Sat, 9 Sep 2023 13:00:25 -0700
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <udiisq$6ih8$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <udigh5$6amo$4@dont-email.me>
<udiiim$6ngs$1@dont-email.me> <udiiqu$6ih8$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 9 Sep 2023 20:00:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="6a3b350a6648114514a7c92794ed6367";
logging-data="215592"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tvEM8NXo+yJax7MFCeGUzpKPwODbsHGI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:Et/8iX1er515Fzw1vMV0NAGwcfs=
Content-Language: en-US
In-Reply-To: <udiiqu$6ih8$2@dont-email.me>
 by: Chris M. Thomasson - Sat, 9 Sep 2023 20:00 UTC

On 9/9/2023 12:59 PM, Chris M. Thomasson wrote:
> On 9/9/2023 12:55 PM, Bonita Montero wrote:
>> Am 09.09.2023 um 21:20 schrieb Chris M. Thomasson:
>>
>>>> It doesn't matter what Posix or Win32 says.
>>
>>> Are you sure about that?
>>
>> The standard is operating system agnostic.
>>
>>> Might fail? For what reasons?
>>
>> F.e. because there's no more non-pageable memory for a semaphore.
>>
>
> An address based hash into a table based approach works by creating
> everything up front. If this fails, then the user program logic is not
> even executed at all.

Just one way.

Re: Thread-safe initialization of static objects

<zI4LM.170544$uEkc.45136@fx35.iad>

  copy mid

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

  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!fx35.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Thread-safe initialization of static objects
Content-Language: en-US
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <udig8l$6ddc$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 14
Message-ID: <zI4LM.170544$uEkc.45136@fx35.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: Sat, 9 Sep 2023 13:37:50 -0700
X-Received-Bytes: 1719
 by: Richard Damon - Sat, 9 Sep 2023 20:37 UTC

On 9/9/23 12:15 PM, Bonita Montero wrote:
> Am 09.09.2023 um 19:42 schrieb Pavel:
>
>> If Microsoft implemented standard wrongly, it's Microsoft's failure,
>> not the standard's.
>
> The standard doesn't say anything to the issue I've shown.
>

The Standard defines the final results that must happen (or
possibilities that can happen in some cases).

If the implementation doesn't meet that result, it is non-conforming and
could be said to have implemented things "wrongly"

Re: Thread-safe initialization of static objects

<0M4LM.170545$uEkc.43152@fx35.iad>

  copy mid

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

  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!fx35.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Thread-safe initialization of static objects
Content-Language: en-US
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me>
From: Rich...@Damon-Family.org (Richard Damon)
In-Reply-To: <udigbv$6ddc$2@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 20
Message-ID: <0M4LM.170545$uEkc.43152@fx35.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: Sat, 9 Sep 2023 13:41:32 -0700
X-Received-Bytes: 2022
 by: Richard Damon - Sat, 9 Sep 2023 20:41 UTC

On 9/9/23 12:17 PM, Bonita Montero wrote:
> Am 09.09.2023 um 20:49 schrieb Chris M. Thomasson:
>
>> Huh? pthread_once totally applies here. Windows has futex like abilities.
>
> It doesn't matter what Posix or Win32 says. The standard should
> honour that static initialization might fail because of creating
> a synchronization primitive or synchronizing on them. The standard
> shoudln't require that this never fails.
>

Why?

Unless you can show that NO method can be created that meet the
requirements, using an insufficient method is just incorrect.

Since the use of a single synchronization primative meets the
requirement, (and a system that can't generate at least one is
insufficient to meet the standard), any system that can't meet the
requirement is just incorrect.

Re: Thread-safe initialization of static objects

<udj9o1$dg67$1@dont-email.me>

  copy mid

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

  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: Sat, 9 Sep 2023 19:30:24 -0700
Organization: A noiseless patient Spider
Lines: 66
Message-ID: <udj9o1$dg67$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbqs7$2t34f$1@dont-email.me> <udbs1f$2t79o$1@dont-email.me>
<udbtda$2tdm8$1@dont-email.me> <udcf19$2vuf5$1@dont-email.me>
<udd6vm$33f8r$1@dont-email.me> <udd87f$33lr1$1@dont-email.me>
<udd90h$33peq$1@dont-email.me> <udda40$33ub2$1@dont-email.me>
<udg01c$3m3qc$2@dont-email.me> <4OOKM.167484$uEkc.38090@fx35.iad>
<udggc7$3ou77$1@dont-email.me> <udggmi$3ou77$2@dont-email.me>
<7p2LM.1449513$GMN3.1325499@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 10 Sep 2023 02:30:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="276b8abcc14edfeeb442d80de57c9759";
logging-data="442567"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19ehhlgorF2wjfQWuA8ORz8gZ+VQbLHobI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:imspeG8zcoQFURRwnGKO4NKNIAE=
In-Reply-To: <7p2LM.1449513$GMN3.1325499@fx16.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Sun, 10 Sep 2023 02:30 UTC

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

Windows has:

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

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

This is their part of their "futex" API:

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

Re: Thread-safe initialization of static objects

<udk0do$h1e9$1@dont-email.me>

  copy mid

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

  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: Sun, 10 Sep 2023 10:57:29 +0200
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <udk0do$h1e9$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 08:57:28 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="35232096b8c55254ca98ac3b8ca6b8cc";
logging-data="558537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/H9H2MGKJgByh7NrJDOcpMKPhb9piNIN8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:fhTKtIbeC9n9as94PeX/SKYdz6Y=
In-Reply-To: <zI4LM.170544$uEkc.45136@fx35.iad>
Content-Language: de-DE
 by: Bonita Montero - Sun, 10 Sep 2023 08:57 UTC

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.

Re: Thread-safe initialization of static objects

<udk0g7$h1e9$2@dont-email.me>

  copy mid

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

  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: Sun, 10 Sep 2023 10:58:49 +0200
Organization: A noiseless patient Spider
Lines: 11
Message-ID: <udk0g7$h1e9$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <udigh5$6amo$4@dont-email.me>
<udiiim$6ngs$1@dont-email.me> <udiiqu$6ih8$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 08:58:47 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="35232096b8c55254ca98ac3b8ca6b8cc";
logging-data="558537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18ZyVGagJouJkfUkHyYjOPtwv72nBojP60="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:LEsFFbmhaEZLDBnzSiUdpHfwRH4=
In-Reply-To: <udiiqu$6ih8$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sun, 10 Sep 2023 08:58 UTC

Am 09.09.2023 um 21:59 schrieb Chris M. Thomasson:

> On 9/9/2023 12:55 PM, Bonita Montero wrote:

>> F.e. because there's no more non-pageable memory for a semaphore.

> An address based hash into a table based approach works by creating
> everything up front. If this fails, then the user program logic is
> not even executed at all.

Do you want to follow in Amine's footsteps ?

Re: Thread-safe initialization of static objects

<udk0hm$h1e9$3@dont-email.me>

  copy mid

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

  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: Sun, 10 Sep 2023 10:59:36 +0200
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <udk0hm$h1e9$3@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <0M4LM.170545$uEkc.43152@fx35.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 08:59:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="35232096b8c55254ca98ac3b8ca6b8cc";
logging-data="558537"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19XyNJo8m3OimqRju+PIP9u6b8rXTEhfgQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:FQP3qSKrM0etRjEJTqAXwUb5eNI=
In-Reply-To: <0M4LM.170545$uEkc.43152@fx35.iad>
Content-Language: de-DE
 by: Bonita Montero - Sun, 10 Sep 2023 08:59 UTC

Am 09.09.2023 um 22:41 schrieb Richard Damon:

> Why?

Because the standard should honour that kernel-synch might fail
on static initialization.

Re: Thread-safe initialization of static objects

<hRjLM.1455228$GMN3.816986@fx16.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer01.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx16.iad.POSTED!not-for-mail
MIME-Version: 1.0
User-Agent: Mozilla Thunderbird
Subject: Re: Thread-safe initialization of static objects
Newsgroups: comp.lang.c++
References: <udafjf$2joeq$1@dont-email.me> <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>
From: Rich...@Damon-Family.org (Richard Damon)
Content-Language: en-US
In-Reply-To: <udk0do$h1e9$1@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 29
Message-ID: <hRjLM.1455228$GMN3.816986@fx16.iad>
X-Complaints-To: abuse@easynews.com
Organization: Forte - www.forteinc.com
X-Complaints-Info: Please be sure to forward a copy of ALL headers otherwise we will be unable to process your complaint properly.
Date: Sun, 10 Sep 2023 06:51:09 -0700
X-Received-Bytes: 2514
 by: Richard Damon - Sun, 10 Sep 2023 13:51 UTC

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), so it is possible, so you can't say the Standard is
asking for impossible behavior, thus any "optimizations" that don't meet
that defined behavior are just WRONG.

Saying something wrong must be made right is just WRONG, so you are
WRONG in your claim.

PERIOD.

Re: Thread-safe initialization of static objects

<udkoc6$kdis$1@dont-email.me>

  copy mid

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

  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: Sun, 10 Sep 2023 17:46:15 +0200
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <udkoc6$kdis$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 15:46:14 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="35232096b8c55254ca98ac3b8ca6b8cc";
logging-data="669276"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BaDoEbPS5IZTXsQ5trTmxQ8qhzyNg1O8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:2IwNB7cTcR6YR/thyqbB+NY1ycY=
Content-Language: de-DE
In-Reply-To: <hRjLM.1455228$GMN3.816986@fx16.iad>
 by: Bonita Montero - Sun, 10 Sep 2023 15:46 UTC

Am 10.09.2023 um 15:51 schrieb Richard Damon:

> You don't seem to understand that sincd it CAN be done in a way that
> always works, ...

A standard shouldn't mandate that this never fails.

> Static Initialization has DEFINED behavior, and that behavior must be
> honored, and the implementation do what is need to make that happen.

Locking-errors while static initialitation are unspecified; whether
they might occur or not on a specific operating system doesn't matter.

Re: Thread-safe initialization of static objects

<udkpmo$knnn$1@dont-email.me>

  copy mid

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

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

10.09.2023 18:46 Bonita Montero kirjutas:
> Am 10.09.2023 um 15:51 schrieb Richard Damon:
>
>> You don't seem to understand that sincd it CAN be done in a way that
>> always works, ...
>
> A standard shouldn't mandate that this never fails.

So suppose the standard committee agrees with you and adds a sentence to
the standard:

Dynamic initialization of a non-local variable with static storage
duration can fail even if its initializing function does not throw, in
which case the behavior is ...undefined... / ..unspecified... /
....calling std::terminate() after unspecified time...

Which variant do you prefer? And how would this help the programmer who
needs to write programs in C++? Should they just avoid creating any
static variables at all, in order to not trigger this failure scenario?

Re: Thread-safe initialization of static objects

<udkq3u$koun$1@dont-email.me>

  copy mid

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

  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: Sun, 10 Sep 2023 18:15:59 +0200
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <udkq3u$koun$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <q82LM.1449511$GMN3.1347862@fx16.iad>
<udig8l$6ddc$1@dont-email.me> <zI4LM.170544$uEkc.45136@fx35.iad>
<udk0do$h1e9$1@dont-email.me> <hRjLM.1455228$GMN3.816986@fx16.iad>
<udkoc6$kdis$1@dont-email.me> <udkpmo$knnn$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 16:15:58 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="35232096b8c55254ca98ac3b8ca6b8cc";
logging-data="680919"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX198RBpaa8UnS7VWby4uOB/Ht95AZV/p8hs="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:bqvml+ano6fdjuHLhGZYR3T6uPA=
In-Reply-To: <udkpmo$knnn$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sun, 10 Sep 2023 16:15 UTC

Am 10.09.2023 um 18:08 schrieb Paavo Helde:

> Which variant do you prefer? And how would this help the programmer who
> needs to write programs in C++? Should they just avoid creating any
> static variables at all, in order to not trigger this failure scenario?

It should be handled like synchronization on a std::mutex,
which can fail with a system_error. If this would happen
the object would remain uninitialized.

Re: Thread-safe initialization of static objects

<vcmLM.868787$U3w1.456645@fx09.iad>

  copy mid

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

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

On 9/10/23 8:46 AM, Bonita Montero wrote:
> Am 10.09.2023 um 15:51 schrieb Richard Damon:
>
>> You don't seem to understand that sincd it CAN be done in a way that
>> always works, ...
>
> A standard shouldn't mandate that this never fails.

You WANT a standard that says even if your program is written totally
correct, the implementation can decide that it will just make it run wrong?

>
>> Static Initialization has DEFINED behavior, and that behavior must be
>> honored, and the implementation do what is need to make that happen.
>
> Locking-errors while static initialitation are unspecified; whether
> they might occur or not on a specific operating system doesn't matter.
>

Since it has been shown that with a simpler locking method, you can
ALWAYS succeed (or die with a resource error before starting user code),
not meeting the requirement is just an error in the implementation.

PERIOD.

ANY operating system that can correctly run multi-threaded code can
handle that. If it can't, it can't actually handle multi-threaded code.

If an "optimization" can cause failures that can't otherwise occur, and
are not allowed by the standard, then that "optimization" isn't allowed
(except by switching to a non-conforming mode).

You don't seem to understand what a "Standard" is.

Re: Thread-safe initialization of static objects

<udl0hv$lp5v$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sun, 10 Sep 2023 11:05:51 -0700
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <udl0hv$lp5v$1@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <udigh5$6amo$4@dont-email.me>
<udiiim$6ngs$1@dont-email.me> <udiiqu$6ih8$2@dont-email.me>
<udk0g7$h1e9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 18:05:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="276b8abcc14edfeeb442d80de57c9759";
logging-data="713919"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18TZIbwCFBo7UeJVnNPmxEWeiXf6MGzMmA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:hgFb3zB/em7ohqNynV/tYAUGfNk=
In-Reply-To: <udk0g7$h1e9$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sun, 10 Sep 2023 18:05 UTC

On 9/10/2023 1:58 AM, Bonita Montero wrote:
> Am 09.09.2023 um 21:59 schrieb Chris M. Thomasson:
>
>> On 9/9/2023 12:55 PM, Bonita Montero wrote:
>
>>> F.e. because there's no more non-pageable memory for a semaphore.
>
>> An address based hash into a table based approach works by creating
>> everything up front. If this fails, then the user program logic is
>> not even executed at all.
>
> Do you want to follow in Amine's footsteps ?

What do you mean by that comment?

Re: Thread-safe initialization of static objects

<udl0n9$lp5v$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Thread-safe initialization of static objects
Date: Sun, 10 Sep 2023 11:08:41 -0700
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <udl0n9$lp5v$2@dont-email.me>
References: <udafjf$2joeq$1@dont-email.me> <1h7KM.66324$Wk53.59929@fx01.iad>
<udbe19$2rk0p$2@dont-email.me> <2acKM.719164$U3w1.269152@fx09.iad>
<udbjfo$2s7cn$1@dont-email.me> <RllKM.1028889$SuUf.692033@fx14.iad>
<udcubm$325k4$1@dont-email.me> <wguKM.698884$xMqa.357246@fx12.iad>
<udebu2$3bknb$1@dont-email.me> <X5KKM.218705$ftCb.30173@fx34.iad>
<udgpnl$3tuni$1@dont-email.me> <udi0vu$488m$1@dont-email.me>
<udi9s5$5f8c$1@dont-email.me> <udieo4$63u7$4@dont-email.me>
<udigbv$6ddc$2@dont-email.me> <udigh5$6amo$4@dont-email.me>
<udiiim$6ngs$1@dont-email.me> <udiiqu$6ih8$2@dont-email.me>
<udk0g7$h1e9$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 10 Sep 2023 18:08:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="276b8abcc14edfeeb442d80de57c9759";
logging-data="713919"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18qq1uKA8+BlmgF6rvHt8RZv8fVnY5EC3c="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.15.0
Cancel-Lock: sha1:UKdauux0WeCl3MOAA9g0dAtzcOs=
In-Reply-To: <udk0g7$h1e9$2@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Sun, 10 Sep 2023 18:08 UTC

On 9/10/2023 1:58 AM, Bonita Montero wrote:
> Am 09.09.2023 um 21:59 schrieb Chris M. Thomasson:
>
>> On 9/9/2023 12:55 PM, Bonita Montero wrote:
>
>>> F.e. because there's no more non-pageable memory for a semaphore.
>
>> An address based hash into a table based approach works by creating
>> everything up front. If this fails, then the user program logic is
>> not even executed at all.
>
> Do you want to follow in Amine's footsteps ?

Iirc, some systems have a large table of mutexes or semaphores created
up front in the kernel itself. They use them for contended futexes to
wait on. A futex is address based, and when they have to block that
index the address into said table. Have you ever used them before? Also,
think of Windows keyed events.

Re: Thread-safe initialization of static objects

<udl0pi$lp5v$3@dont-email.me>

  copy mid

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

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

On 9/10/2023 1:59 AM, Bonita Montero wrote:
> Am 09.09.2023 um 22:41 schrieb Richard Damon:
>
>> Why?
>
> Because the standard should honour that kernel-synch might fail
> on static initialization.
>

Strange answer. Humm...

Re: Thread-safe initialization of static objects

<udl0ti$lp5v$4@dont-email.me>

  copy mid

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

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

On 9/10/2023 1:59 AM, Bonita Montero wrote:
> Am 09.09.2023 um 22:41 schrieb Richard Damon:
>
>> Why?
>
> Because the standard should honour that kernel-synch might fail
> on static initialization.
>

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

Re: Thread-safe initialization of static objects

<udl0v2$lp5v$5@dont-email.me>

  copy mid

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

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

On 9/10/2023 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.
>

What error?

Re: Thread-safe initialization of static objects

<udl117$lp5v$6@dont-email.me>

  copy mid

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

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

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

then what?

Re: Thread-safe initialization of static objects

<udl11l$lp5v$7@dont-email.me>

  copy mid

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

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

On 9/10/2023 9:32 AM, Richard Damon wrote:
> On 9/10/23 8:46 AM, Bonita Montero wrote:
>> Am 10.09.2023 um 15:51 schrieb Richard Damon:
>>
>>> You don't seem to understand that sincd it CAN be done in a way that
>>> always works, ...
>>
>> A standard shouldn't mandate that this never fails.
>
> You WANT a standard that says even if your program is written totally
> correct, the implementation can decide that it will just make it run wrong?
>
>>
>>> Static Initialization has DEFINED behavior, and that behavior must be
>>> honored, and the implementation do what is need to make that happen.
>>
>> Locking-errors while static initialitation are unspecified; whether
>> they might occur or not on a specific operating system doesn't matter.
>>
>
> Since it has been shown that with a simpler locking method, you can
> ALWAYS succeed (or die with a resource error before starting user code),
> not meeting the requirement is just an error in the implementation.
>
> PERIOD.
>
> ANY operating system that can correctly run multi-threaded code can
> handle that. If it can't, it can't actually handle multi-threaded code.
>
> If an "optimization" can cause failures that can't otherwise occur, and
> are not allowed by the standard, then that "optimization" isn't allowed
> (except by switching to a non-conforming mode).
>
>
> You don't seem to understand what a "Standard" is.

Ditto.


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

Pages:123456789101112131415161718192021222324252627
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor