Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Money is the root of all money." -- the moving finger


devel / comp.lang.c++ / A Java- / .NET-like monitor

SubjectAuthor
* A Java- / .NET-like monitorBonita Montero
+* Re: A Java- / .NET-like monitorBonita Montero
|`* Re: A Java- / .NET-like monitorChris M. Thomasson
| +* Re: A Java- / .NET-like monitorChris M. Thomasson
| |+* Re: A Java- / .NET-like monitorBonita Montero
| ||`- Re: A Java- / .NET-like monitorChris M. Thomasson
| |`- Re: A Java- / .NET-like monitorChris M. Thomasson
| `* Re: A Java- / .NET-like monitorBonita Montero
|  `- Re: A Java- / .NET-like monitorChris M. Thomasson
+* Re: A Java- / .NET-like monitorKaz Kylheku
|`* Re: A Java- / .NET-like monitorBonita Montero
| `* Re: A Java- / .NET-like monitorKaz Kylheku
|  `* Re: A Java- / .NET-like monitorBonita Montero
|   +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   |`* Re: A Java- / .NET-like monitorKaz Kylheku
|   | `- Re: A Java- / .NET-like monitorChris M. Thomasson
|   +* Re: A Java- / .NET-like monitorKaz Kylheku
|   |`* Re: A Java- / .NET-like monitorBonita Montero
|   | +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |`* Re: A Java- / .NET-like monitorBonita Montero
|   | | `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |  `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |+- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |`* Re: A Java- / .NET-like monitorBonita Montero
|   | |   | `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |  `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |+- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |`* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   | `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |  +- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |  `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |   `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |`* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    | `- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    +* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |`* Re: A Java- / .NET-like monitorPavel
|   | |   |   |    | `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |  `* Re: A Java- / .NET-like monitorPavel
|   | |   |   |    |   `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |    `* Re: A Java- / .NET-like monitorPavel
|   | |   |   |    |     +- Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     +* Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     |+* Re: A Java- / .NET-like monitorKaz Kylheku
|   | |   |   |    |     ||+- Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     ||+- Re: A Java- / .NET-like monitorPavel
|   | |   |   |    |     ||`* Re: A Java- / .NET-like monitorMichael S
|   | |   |   |    |     || `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||  `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||   `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||    +- Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||    `* Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     ||     `* Re: A Java- / .NET-like monitorKaz Kylheku
|   | |   |   |    |     ||      +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      |`* Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     ||      | +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      | |`- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      | `* Re: A Java- / .NET-like monitorFred. Zwarts
|   | |   |   |    |     ||      |  `* Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     ||      |   `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||      |    `- Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     ||      +* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||      |`* Re: A Java- / .NET-like monitorKaz Kylheku
|   | |   |   |    |     ||      | `* Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     ||      |  +- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      |  `* Re: A Java- / .NET-like monitorMichael S
|   | |   |   |    |     ||      |   +- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      |   `* Re: A Java- / .NET-like monitorDavid Brown
|   | |   |   |    |     ||      |    +* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||      |    |+* Re: A Java- / .NET-like monitorDavid Brown
|   | |   |   |    |     ||      |    ||`* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||      |    || `* Re: A Java- / .NET-like monitorDavid Brown
|   | |   |   |    |     ||      |    ||  +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      |    ||  |`- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      |    ||  `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||      |    ||   `* Re: A Java- / .NET-like monitorDavid Brown
|   | |   |   |    |     ||      |    ||    `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||      |    ||     `* Re: A Java- / .NET-like monitorDavid Brown
|   | |   |   |    |     ||      |    ||      `- Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     ||      |    |`- Re: A Java- / .NET-like monitorScott Lurndal
|   | |   |   |    |     ||      |    `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     ||      |     `- Re: A Java- / .NET-like monitorDavid Brown
|   | |   |   |    |     ||      `- Re: A Java- / .NET-like monitorDavid Brown
|   | |   |   |    |     |+- Re: A Java- / .NET-like monitorPavel
|   | |   |   |    |     |`* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     | `* Re: A Java- / .NET-like monitorKaz Kylheku
|   | |   |   |    |     |  `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     |   `* Re: A Java- / .NET-like monitorKaz Kylheku
|   | |   |   |    |     |    `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     |     `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     |      +* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     |      |`- Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     |      `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     |       `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     |        `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     |         `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     |          `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     |           `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    |     |            `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   |    |     `* Re: A Java- / .NET-like monitorChris M. Thomasson
|   | |   |   |    `* Re: A Java- / .NET-like monitorBonita Montero
|   | |   |   `- Re: A Java- / .NET-like monitorBonita Montero
|   | |   `* Re: A Java- / .NET-like monitorPavel
|   | `* Re: A Java- / .NET-like monitorKaz Kylheku
|   `* Re: A Java- / .NET-like monitorChris M. Thomasson
+* Re: A Java- / .NET-like monitorBonita Montero
`* Re: A Java- / .NET-like monitorBonita Montero

Pages:1234567891011
Re: A Java- / .NET-like monitor

<uj38g6$1skku$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Wed, 15 Nov 2023 12:08:37 -0800
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <uj38g6$1skku$2@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<20231112091106.817@kylheku.com>
<uisfvu$gsmo$1@raubtier-asyl.eternal-september.org>
<uisgpc$h32u$1@raubtier-asyl.eternal-september.org>
<uiu26e$sper$1@dont-email.me>
<uiv020$148s1$1@raubtier-asyl.eternal-september.org>
<uiv050$1462e$1@dont-email.me>
<uiv50o$14quu$1@raubtier-asyl.eternal-september.org>
<WcM4N.53198$svP4.12968@fx12.iad>
<uj04oh$19j9e$1@raubtier-asyl.eternal-september.org>
<mZM4N.10239$rx%7.6902@fx47.iad> <uj0l38$1ch3f$1@dont-email.me>
<uj1j2q$1kad4$2@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Nov 2023 20:08:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c1eb1e7d2816baa503f549a694bca0e3";
logging-data="1987230"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gRLvVrQhquuSF314lNDKfW59H0nmDPA0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:E+4iI9sNDNph7oa2nZpzZZ05lzQ=
In-Reply-To: <uj1j2q$1kad4$2@raubtier-asyl.eternal-september.org>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 15 Nov 2023 20:08 UTC

On 11/14/2023 8:57 PM, Bonita Montero wrote:
> Am 14.11.2023 um 21:25 schrieb Chris M. Thomasson:
>
>> Well, we have cmpxchg8b on 32-bit Intel...
>
> That's what I also thought, i.e. you can make a 64 bit store with that.
> But that's for sure much slower than the trick with the x87-FPU I've
> shown.
>
>

Are you sure its 100% atomic for use in multi-thread sync algorithms?

Re: A Java- / .NET-like monitor

<uj38lm$1skku$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Wed, 15 Nov 2023 12:11:33 -0800
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <uj38lm$1skku$3@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad>
<20231112204849.10@kylheku.com> <euB4N.6863$%p%e.3900@fx43.iad>
<20231113192822.953@kylheku.com> <97V4N.19464$Wzw6.11650@fx13.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Wed, 15 Nov 2023 20:11:34 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c1eb1e7d2816baa503f549a694bca0e3";
logging-data="1987230"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19kNMkK+M06ad9nJd14Fpu74uGXC3/yn00="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:nAQMgb1Idh3P+cypnlUEU5GOQr8=
In-Reply-To: <97V4N.19464$Wzw6.11650@fx13.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 15 Nov 2023 20:11 UTC

On 11/14/2023 5:26 PM, Pavel wrote:
> Kaz Kylheku wrote:
>> On 2023-11-14, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>
>> wrote:
>>> Kaz Kylheku wrote:
>>>> Because of the situation that the thread which was signaled is
>>>> trying to acquire the mutex, which, stupidly, the signaling thread
>>>> is still holding. So, oops, back it goes into suspended state, and we
>>>> have to context switch to the mutex holder which has to release the
>>>> mutex and then switch to that signaled thread again.
>>>>
>>> Please see my response to your other post. "as-if" calling of
>>> pthread_mutex_lock does not prescribe actually calling it. Nothing in
>>> the standard prevents pthread_cond_signal from doing all the job of
>>> stuffing the unblocked threads to the mutex waiting list in accordance
>>> with some scheduling policy.
>>
>> Have you noticed how no mutex appears in the pthread_cond_signal API?
>>
> Of course but so what? Nothing prevents the implementation from listing
> the temporarily released mutices of the waiting pthread_cond_wait
> callers in the cond var where pthread_cond_signal can access them.
>
> Or, possibly even better, keeping a pointer to them with the threads
> waiting  for the condvar (there can only be at most one such temporarily
> released mutex per the waiting thread). And the threads waiting for the
> condvar are accessible for the pthread_cond_signal according to the spec.

Just as long as the implementation works wrt calling
pthread_cond_signal/broadcast outside of the mutex. If not, it is broken.

Re: A Java- / .NET-like monitor

<uj3939$1skku$4@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Wed, 15 Nov 2023 12:18:48 -0800
Organization: A noiseless patient Spider
Lines: 33
Message-ID: <uj3939$1skku$4@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108100351.347@kylheku.com>
<uigk5o$1nmku$1@raubtier-asyl.eternal-september.org>
<20231108114723.256@kylheku.com>
<uigp4n$1onpc$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com> <E5e4N.6986$Ubzd.3639@fx36.iad>
<20231112203949.483@kylheku.com> <6nB4N.2145$qqwd.2132@fx42.iad>
<20231113191446.974@kylheku.com> <uiv0ib$149hi$1@dont-email.me>
<uiv0k9$149hi$2@dont-email.me> <MqV4N.60715$wvv7.6028@fx14.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Nov 2023 20:18:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c1eb1e7d2816baa503f549a694bca0e3";
logging-data="1987230"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187rNBTlH25NVQUI9AILWIqvmnYEWSKPzc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:1aQ8wvQFsyfaPOR0+mPZmzL7vbA=
Content-Language: en-US
In-Reply-To: <MqV4N.60715$wvv7.6028@fx14.iad>
 by: Chris M. Thomasson - Wed, 15 Nov 2023 20:18 UTC

On 11/14/2023 5:47 PM, Pavel wrote:
> Chris M. Thomasson wrote:
>> On 11/13/2023 9:28 PM, Chris M. Thomasson wrote:
>>> On 11/13/2023 7:27 PM, Kaz Kylheku wrote:
>>>> On 2023-11-14, Pavel
>>>> <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
>>>>> "as-if" and "according to the scheduling policy (if applicable)" here
>>>>> are important. The standard intent may be to permit only the threads
>>>>> that are "unblocked" contend for the mutex -- as opposed to all
>>>>> non-blocked threads.
>>>>
>>>> It's possible that only one thread is unblocked by a
>>>> pthread_cond_signal. It takes at least two parties to contend for
>>>> something.
>>>>
>>>
>>> A signalling thread does its thing while holding the mutex... Well,
>>> it hears the following playing in the background:
>>>
>>> https://youtu.be/7YvAYIJSSZY
>>
>> A condvar that cannot signal/broadcast from outside of a held mutex is
>> broken by default.
> It can, it's just that the desired scheduling policy cannot be
> *effectively* applied if a program signal outside of that mutex.
>
> E.g. in some scenario a higher-prio thread could stay indefinitely
> starved by the lower-prio thread, regardless of the thread library
> implementation.

Afaict, it is an implementation detail. Say, SCHED_FIFO, the impl shall
strive to honor this. If it has to use a bakery algorithm to do it, so
be it.

Re: A Java- / .NET-like monitor

<uj396r$1spi2$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Wed, 15 Nov 2023 12:20:42 -0800
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <uj396r$1spi2$1@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108100351.347@kylheku.com>
<uigk5o$1nmku$1@raubtier-asyl.eternal-september.org>
<20231108114723.256@kylheku.com>
<uigp4n$1onpc$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com> <E5e4N.6986$Ubzd.3639@fx36.iad>
<20231112203949.483@kylheku.com> <6nB4N.2145$qqwd.2132@fx42.iad>
<20231113191446.974@kylheku.com> <uiv0ib$149hi$1@dont-email.me>
<uiv0k9$149hi$2@dont-email.me> <MqV4N.60715$wvv7.6028@fx14.iad>
<uj3939$1skku$4@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Nov 2023 20:20:43 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c1eb1e7d2816baa503f549a694bca0e3";
logging-data="1992258"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18+JcXGeQUJhNrmiAwfD2ng3IxxCIGyn/o="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zZ57U+HVBqXfz8NqLbsZ9QrRm3k=
In-Reply-To: <uj3939$1skku$4@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 15 Nov 2023 20:20 UTC

On 11/15/2023 12:18 PM, Chris M. Thomasson wrote:
> On 11/14/2023 5:47 PM, Pavel wrote:
>> Chris M. Thomasson wrote:
>>> On 11/13/2023 9:28 PM, Chris M. Thomasson wrote:
>>>> On 11/13/2023 7:27 PM, Kaz Kylheku wrote:
>>>>> On 2023-11-14, Pavel
>>>>> <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
>>>>>> "as-if" and "according to the scheduling policy (if applicable)" here
>>>>>> are important. The standard intent may be to permit only the threads
>>>>>> that are "unblocked" contend for the mutex -- as opposed to all
>>>>>> non-blocked threads.
>>>>>
>>>>> It's possible that only one thread is unblocked by a
>>>>> pthread_cond_signal. It takes at least two parties to contend for
>>>>> something.
>>>>>
>>>>
>>>> A signalling thread does its thing while holding the mutex... Well,
>>>> it hears the following playing in the background:
>>>>
>>>> https://youtu.be/7YvAYIJSSZY
>>>
>>> A condvar that cannot signal/broadcast from outside of a held mutex
>>> is broken by default.
>> It can, it's just that the desired scheduling policy cannot be
>> *effectively* applied if a program signal outside of that mutex.
>>
>> E.g. in some scenario a higher-prio thread could stay indefinitely
>> starved by the lower-prio thread, regardless of the thread library
>> implementation.
>
> Afaict, it is an implementation detail. Say, SCHED_FIFO, the impl shall
> strive to honor this. If it has to use a bakery algorithm to do it, so
> be it.

Also, you as the programmer can choose to signal within a locked region.
No problem.

Re: A Java- / .NET-like monitor

<uj398l$1spi2$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Wed, 15 Nov 2023 12:21:41 -0800
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <uj398l$1spi2$2@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uinloo$3d813$1@raubtier-asyl.eternal-september.org>
<uio76q$3gj34$1@raubtier-asyl.eternal-september.org>
<uiolf0$3j4r2$3@dont-email.me>
<uipl0g$3su3r$1@raubtier-asyl.eternal-september.org>
<uirdja$7lqi$1@dont-email.me>
<uivd74$15vdk$1@raubtier-asyl.eternal-september.org>
<uive6t$163u2$2@dont-email.me>
<uivgf2$16drp$1@raubtier-asyl.eternal-september.org>
<uivgu9$16cth$1@dont-email.me>
<uivhqg$16kjm$1@raubtier-asyl.eternal-september.org>
<uj0l74$1ch3e$1@dont-email.me>
<uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Nov 2023 20:21:41 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="c1eb1e7d2816baa503f549a694bca0e3";
logging-data="1992258"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1928dt9XygR5Pxwjl8No4RL1C5pNHgvCgk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:Cw1k9uewd8o1juasZ6Hwh04sefA=
In-Reply-To: <uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 15 Nov 2023 20:21 UTC

On 11/14/2023 8:54 PM, Bonita Montero wrote:
> Am 14.11.2023 um 21:27 schrieb Chris M. Thomasson:
>> On 11/14/2023 2:23 AM, Bonita Montero wrote:
>>> Am 14.11.2023 um 11:08 schrieb Chris M. Thomasson:
>>>
>>>> So, you are finished with any future on the fly corrections, right?
>>>
>>> I'm currently not missing anything with the code.
>>
>> Okay, can you please make a new post that contains the finished code?
>
> I already posted the finished code in two parts with this little
> correction (missing "!"). The xhandle.h is still the same.
>
>

Correction? Just post the 100% finished code in a brand new thread.

Re: A Java- / .NET-like monitor

<20231115122730.814@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Wed, 15 Nov 2023 21:26:26 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 111
Message-ID: <20231115122730.814@kylheku.com>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108100351.347@kylheku.com>
<uigk5o$1nmku$1@raubtier-asyl.eternal-september.org>
<20231108114723.256@kylheku.com>
<uigp4n$1onpc$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com> <E5e4N.6986$Ubzd.3639@fx36.iad>
<20231112203949.483@kylheku.com> <6nB4N.2145$qqwd.2132@fx42.iad>
<20231113191446.974@kylheku.com> <uiv0ib$149hi$1@dont-email.me>
<uiv0k9$149hi$2@dont-email.me> <MqV4N.60715$wvv7.6028@fx14.iad>
Injection-Date: Wed, 15 Nov 2023 21:26:26 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="8f70237f19fb8d2d6e9e04647f20f101";
logging-data="2013893"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/eIb364r+z4m/c7POHDxz4LpxRAWajaIo="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:JYU/joigtwRyzWqFg0kdxhqyYcI=
 by: Kaz Kylheku - Wed, 15 Nov 2023 21:26 UTC

On 2023-11-15, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
> Chris M. Thomasson wrote:
>> On 11/13/2023 9:28 PM, Chris M. Thomasson wrote:
>>> On 11/13/2023 7:27 PM, Kaz Kylheku wrote:
>>>> On 2023-11-14, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>
>>>> wrote:
>>>>> "as-if" and "according to the scheduling policy (if applicable)" here
>>>>> are important. The standard intent may be to permit only the threads
>>>>> that are "unblocked" contend for the mutex -- as opposed to all
>>>>> non-blocked threads.
>>>>
>>>> It's possible that only one thread is unblocked by a
>>>> pthread_cond_signal. It takes at least two parties to contend for
>>>> something.
>>>>
>>>
>>> A signalling thread does its thing while holding the mutex... Well, it
>>> hears the following playing in the background:
>>>
>>> https://youtu.be/7YvAYIJSSZY
>>
>> A condvar that cannot signal/broadcast from outside of a held mutex is
>> broken by default.
> It can, it's just that the desired scheduling policy cannot be
> *effectively* applied if a program signal outside of that mutex.
>
> E.g. in some scenario a higher-prio thread could stay indefinitely
> starved by the lower-prio thread, regardless of the thread library
> implementation.

I don't see what difference it can actually make, other than in
situations when a thread receives a priority boost while holding a
mutex.

Only one of these is true: (1) either the pthread_cond_signal and
pthread_cond_broadcast functions transfer threads from waiting on the
condition to waiting on the mutex, or (2) they don't: threads are woken,
and have to execute an operation equivalent to pthread_mutex_lock.

(Though there is no mutex argument in the API, the thread is waiting
with respect to a particular mutex. Each thread waiting on the same
condition could nominate a different mutex. So for each thread waiting
on a condition, we know which mutex it released in doing so and can
transfer it to wait on the mutex.)

If the pthread_cond_signal function transfers a thread from the
condition to the mutex according to (1), then everything is cool with
regard to scheduling.

Whether we have this:

pthread_mutex_unlock(&m);
pthread_cond_signal(&c);

...

// re-acquire
pthread_mutex_lock(&m);

or this:

pthread_cond_signal(&c);

pthread_mutex_unlock(&m);

...
// re-acquire
pthread_mutex_lock(&m);

the most important thing is that the waiting threads are already
transferred to waiting on the mutex, before the signaling thread call
tries to re-acquire the mutex.

I.e. the woken threads always reach the mutex wait first, regardless of
these two orders of operations on the part of the signaling thread.

On the other hand, if the pthread_cond_signal operation just wakes up
the threads, such that they themselves have to call the equivalent of
pthread_mutex_lock to reacquire the mutex, we do not gain any special
guarantees in one order or the other. Under either order of the
statements, the signaling thread can snatch the mutex away from the
signaled threads, when reaching the pthread_mutex_lock call,
even if it is a low priority thread and the others are high.

Now with real-time priorities and mutexes that prevent priority
inversion, we could have the following situation:

While a low-priority thread holds a mutex, it is temporarily boosted to
the highest priority from among the set of threads waiting for that
mutex.

There we have a difference between signaling inside or outside, the
reason being that when the thread leaves the mutex to signal outside, it
loses the temporary priority boost. That could lead to an undue delay in
signaling the condition.

The statement in the POSIX standard about predictable scheduling
behavior is like recommending sleep calls to for obtaining more
predictable behavior in a program riddled with race conditions.

If I'm an implementor reading that statement, I cannot infer any
concrete requirements about what it is that I'm supposed to do in
pthread_cond_signal to bring about more predictable scheduling.

Specifications should give specific requirements, not vague opinions.

--
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: A Java- / .NET-like monitor

<uj40j0$23vlu$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 03:59:47 +0100
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <uj40j0$23vlu$1@raubtier-asyl.eternal-september.org>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<20231112091106.817@kylheku.com>
<uisfvu$gsmo$1@raubtier-asyl.eternal-september.org>
<uisgpc$h32u$1@raubtier-asyl.eternal-september.org>
<uiu26e$sper$1@dont-email.me>
<uiv020$148s1$1@raubtier-asyl.eternal-september.org>
<uiv050$1462e$1@dont-email.me>
<uiv50o$14quu$1@raubtier-asyl.eternal-september.org>
<WcM4N.53198$svP4.12968@fx12.iad>
<uj04oh$19j9e$1@raubtier-asyl.eternal-september.org>
<mZM4N.10239$rx%7.6902@fx47.iad> <uj0l38$1ch3f$1@dont-email.me>
<uj1j2q$1kad4$2@raubtier-asyl.eternal-september.org>
<uj38g6$1skku$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Nov 2023 02:59:44 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="6a95c263ed22598a6a8075ff646bc665";
logging-data="2227902"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/rFtvp7yrYQceXMgsybIOB8+ATNAfilw0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:HaNpXCKlgl3AOgdTL7edAnJnwiY=
In-Reply-To: <uj38g6$1skku$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Nov 2023 02:59 UTC

Am 15.11.2023 um 21:08 schrieb Chris M. Thomasson:

> Are you sure its 100% atomic for use in multi-thread sync algorithms?

If MSVC generates that code it's atomic.

Re: A Java- / .NET-like monitor

<uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 04:00:30 +0100
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uinloo$3d813$1@raubtier-asyl.eternal-september.org>
<uio76q$3gj34$1@raubtier-asyl.eternal-september.org>
<uiolf0$3j4r2$3@dont-email.me>
<uipl0g$3su3r$1@raubtier-asyl.eternal-september.org>
<uirdja$7lqi$1@dont-email.me>
<uivd74$15vdk$1@raubtier-asyl.eternal-september.org>
<uive6t$163u2$2@dont-email.me>
<uivgf2$16drp$1@raubtier-asyl.eternal-september.org>
<uivgu9$16cth$1@dont-email.me>
<uivhqg$16kjm$1@raubtier-asyl.eternal-september.org>
<uj0l74$1ch3e$1@dont-email.me>
<uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
<uj398l$1spi2$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Nov 2023 03:00:27 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="6a95c263ed22598a6a8075ff646bc665";
logging-data="2227902"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EryjSNeabQdo2+kpakT6k/Ju8FYuv8Pc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CN41/1nNV/GUJBRU4UNw3jfZFz0=
In-Reply-To: <uj398l$1spi2$2@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Nov 2023 03:00 UTC

Am 15.11.2023 um 21:21 schrieb Chris M. Thomasson:

> Correction? Just post the 100% finished code in a brand new thread.

I've postet everything that is necessary, you only have to add a "!".

Re: A Java- / .NET-like monitor

<uj417p$2436t$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Wed, 15 Nov 2023 19:10:47 -0800
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <uj417p$2436t$1@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uinloo$3d813$1@raubtier-asyl.eternal-september.org>
<uio76q$3gj34$1@raubtier-asyl.eternal-september.org>
<uiolf0$3j4r2$3@dont-email.me>
<uipl0g$3su3r$1@raubtier-asyl.eternal-september.org>
<uirdja$7lqi$1@dont-email.me>
<uivd74$15vdk$1@raubtier-asyl.eternal-september.org>
<uive6t$163u2$2@dont-email.me>
<uivgf2$16drp$1@raubtier-asyl.eternal-september.org>
<uivgu9$16cth$1@dont-email.me>
<uivhqg$16kjm$1@raubtier-asyl.eternal-september.org>
<uj0l74$1ch3e$1@dont-email.me>
<uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
<uj398l$1spi2$2@dont-email.me>
<uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Nov 2023 03:10:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3af96b48525dafea7d7b80955cb07c1c";
logging-data="2231517"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18O9wcUA6OthM4ZLiDevQrJcd4I5tNSXPw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JzMdDgNzkHiS/s5RnQjyCsgQgRs=
In-Reply-To: <uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 16 Nov 2023 03:10 UTC

On 11/15/2023 7:00 PM, Bonita Montero wrote:
> Am 15.11.2023 um 21:21 schrieb Chris M. Thomasson:
>
>> Correction? Just post the 100% finished code in a brand new thread.
>
> I've postet everything that is necessary, you only have to add a "!".
>

Wow... Anyway, where do I add this "!"?

Re: A Java- / .NET-like monitor

<20231115192111.364@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 03:21:49 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 12
Message-ID: <20231115192111.364@kylheku.com>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uinloo$3d813$1@raubtier-asyl.eternal-september.org>
<uio76q$3gj34$1@raubtier-asyl.eternal-september.org>
<uiolf0$3j4r2$3@dont-email.me>
<uipl0g$3su3r$1@raubtier-asyl.eternal-september.org>
<uirdja$7lqi$1@dont-email.me>
<uivd74$15vdk$1@raubtier-asyl.eternal-september.org>
<uive6t$163u2$2@dont-email.me>
<uivgf2$16drp$1@raubtier-asyl.eternal-september.org>
<uivgu9$16cth$1@dont-email.me>
<uivhqg$16kjm$1@raubtier-asyl.eternal-september.org>
<uj0l74$1ch3e$1@dont-email.me>
<uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
<uj398l$1spi2$2@dont-email.me>
<uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>
<uj417p$2436t$1@dont-email.me>
Injection-Date: Thu, 16 Nov 2023 03:21:49 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0273816523bc6b1f85f67c0e763a6e86";
logging-data="2234656"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18gDOfLLI5Ma2t8AGHImcKth4jgXd7gw0o="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:eb+vKT8ddSspDJelTetxXjh9tjM=
 by: Kaz Kylheku - Thu, 16 Nov 2023 03:21 UTC

On 2023-11-16, Chris M. Thomasson <chris.m.thomasson.1@gmail.com> wrote:
> On 11/15/2023 7:00 PM, Bonita Montero wrote:
>> Am 15.11.2023 um 21:21 schrieb Chris M. Thomasson:
>>
>>> Correction? Just post the 100% finished code in a brand new thread.
>>
>> I've postet everything that is necessary, you only have to add a "!".
>>
>
> Wow... Anyway, where do I add this "!"?

I would guess, in front of "necessary".

Re: A Java- / .NET-like monitor

<EAg5N.8455$pgLd.5478@fx05.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx05.iad.POSTED!not-for-mail
Subject: Re: A Java- / .NET-like monitor
Newsgroups: comp.lang.c++
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad>
<20231112204849.10@kylheku.com> <euB4N.6863$%p%e.3900@fx43.iad>
<20231113192822.953@kylheku.com> <97V4N.19464$Wzw6.11650@fx13.iad>
<uj38lm$1skku$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.1
MIME-Version: 1.0
In-Reply-To: <uj38lm$1skku$3@dont-email.me>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Lines: 42
Message-ID: <EAg5N.8455$pgLd.5478@fx05.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Thu, 16 Nov 2023 04:08:04 UTC
Date: Wed, 15 Nov 2023 23:07:58 -0500
X-Received-Bytes: 3454
 by: Pavel - Thu, 16 Nov 2023 04:07 UTC

Chris M. Thomasson wrote:
> On 11/14/2023 5:26 PM, Pavel wrote:
>> Kaz Kylheku wrote:
>>> On 2023-11-14, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>
>>> wrote:
>>>> Kaz Kylheku wrote:
>>>>> Because of the situation that the thread which was signaled is
>>>>> trying to acquire the mutex, which, stupidly, the signaling thread
>>>>> is still holding. So, oops, back it goes into suspended state, and we
>>>>> have to context switch to the mutex holder which has to release the
>>>>> mutex and then switch to that signaled thread again.
>>>>>
>>>> Please see my response to your other post. "as-if" calling of
>>>> pthread_mutex_lock does not prescribe actually calling it. Nothing in
>>>> the standard prevents pthread_cond_signal from doing all the job of
>>>> stuffing the unblocked threads to the mutex waiting list in accordance
>>>> with some scheduling policy.
>>>
>>> Have you noticed how no mutex appears in the pthread_cond_signal API?
>>>
>> Of course but so what? Nothing prevents the implementation from
>> listing the temporarily released mutices of the waiting
>> pthread_cond_wait callers in the cond var where pthread_cond_signal
>> can access them.
>>
>> Or, possibly even better, keeping a pointer to them with the threads
>> waiting  for the condvar (there can only be at most one such
>> temporarily released mutex per the waiting thread). And the threads
>> waiting for the condvar are accessible for the pthread_cond_signal
>> according to the spec.
>
> Just as long as the implementation works wrt calling
> pthread_cond_signal/broadcast outside of the mutex. If not, it is broken.

I am unsure where from that discussion of implementation came. The
*spec* permits this (signalling without holding the mutex), just warns
that a predictable scheduling behavior cannot be achieved then.

What would you consider an example of a "non-working" implementation?

Does my example that illustrates how a higher-prio thread may never make
progress is of a broken implementation in your opinion?

Re: A Java- / .NET-like monitor

<3Jh5N.56974$svP4.10382@fx12.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!feeder1.feed.usenet.farm!feed.usenet.farm!peer03.ams4!peer.am4.highwinds-media.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx12.iad.POSTED!not-for-mail
Subject: Re: A Java- / .NET-like monitor
Newsgroups: comp.lang.c++
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108100351.347@kylheku.com>
<uigk5o$1nmku$1@raubtier-asyl.eternal-september.org>
<20231108114723.256@kylheku.com>
<uigp4n$1onpc$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com> <E5e4N.6986$Ubzd.3639@fx36.iad>
<20231112203949.483@kylheku.com> <6nB4N.2145$qqwd.2132@fx42.iad>
<20231113191446.974@kylheku.com> <uiv0ib$149hi$1@dont-email.me>
<uiv0k9$149hi$2@dont-email.me> <MqV4N.60715$wvv7.6028@fx14.iad>
<20231115122730.814@kylheku.com>
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.1
MIME-Version: 1.0
In-Reply-To: <20231115122730.814@kylheku.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 139
Message-ID: <3Jh5N.56974$svP4.10382@fx12.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Thu, 16 Nov 2023 05:25:19 UTC
Date: Thu, 16 Nov 2023 00:25:19 -0500
X-Received-Bytes: 7917
 by: Pavel - Thu, 16 Nov 2023 05:25 UTC

Kaz Kylheku wrote:
> On 2023-11-15, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
>> Chris M. Thomasson wrote:
>>> On 11/13/2023 9:28 PM, Chris M. Thomasson wrote:
>>>> On 11/13/2023 7:27 PM, Kaz Kylheku wrote:
>>>>> On 2023-11-14, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo>
>>>>> wrote:
>>>>>> "as-if" and "according to the scheduling policy (if applicable)" here
>>>>>> are important. The standard intent may be to permit only the threads
>>>>>> that are "unblocked" contend for the mutex -- as opposed to all
>>>>>> non-blocked threads.
>>>>>
>>>>> It's possible that only one thread is unblocked by a
>>>>> pthread_cond_signal. It takes at least two parties to contend for
>>>>> something.
>>>>>
>>>>
>>>> A signalling thread does its thing while holding the mutex... Well, it
>>>> hears the following playing in the background:
>>>>
>>>> https://youtu.be/7YvAYIJSSZY
>>>
>>> A condvar that cannot signal/broadcast from outside of a held mutex is
>>> broken by default.
>> It can, it's just that the desired scheduling policy cannot be
>> *effectively* applied if a program signal outside of that mutex.
>>
>> E.g. in some scenario a higher-prio thread could stay indefinitely
>> starved by the lower-prio thread, regardless of the thread library
>> implementation.
>
> I don't see what difference it can actually make, other than in
> situations when a thread receives a priority boost while holding a
> mutex.
>
> Only one of these is true: (1) either the pthread_cond_signal and
> pthread_cond_broadcast functions transfer threads from waiting on the
> condition to waiting on the mutex, or (2) they don't: threads are woken,
> and have to execute an operation equivalent to pthread_mutex_lock.
>
> (Though there is no mutex argument in the API, the thread is waiting
> with respect to a particular mutex. Each thread waiting on the same
> condition could nominate a different mutex. So for each thread waiting
> on a condition, we know which mutex it released in doing so and can
> transfer it to wait on the mutex.)
>
> If the pthread_cond_signal function transfers a thread from the
> condition to the mutex according to (1), then everything is cool with
> regard to scheduling.
>
> Whether we have this:
>
> pthread_mutex_unlock(&m);
> pthread_cond_signal(&c);
>
> ...
>
> // re-acquire
> pthread_mutex_lock(&m);
>
> or this:
>
> pthread_cond_signal(&c);
>
> pthread_mutex_unlock(&m);
>
> ...
> // re-acquire
> pthread_mutex_lock(&m);
>
> the most important thing is that the waiting threads are already
> transferred to waiting on the mutex, before the signaling thread call
> tries to re-acquire the mutex.
>
> I.e. the woken threads always reach the mutex wait first, regardless of
> these two orders of operations on the part of the signaling thread.
>
> On the other hand, if the pthread_cond_signal operation just wakes up
> the threads, such that they themselves have to call the equivalent of
> pthread_mutex_lock to reacquire the mutex, we do not gain any special
> guarantees in one order or the other. Under either order of the
> statements, the signaling thread can snatch the mutex away from the
> signaled threads, when reaching the pthread_mutex_lock call,
> even if it is a low priority thread and the others are high.
>
> Now with real-time priorities and mutexes that prevent priority
> inversion, we could have the following situation:
>
> While a low-priority thread holds a mutex, it is temporarily boosted to
> the highest priority from among the set of threads waiting for that
> mutex.
>
> There we have a difference between signaling inside or outside, the
> reason being that when the thread leaves the mutex to signal outside, it
> loses the temporary priority boost. That could lead to an undue delay in
> signaling the condition.
>
> The statement in the POSIX standard about predictable scheduling
> behavior is like recommending sleep calls to for obtaining more
> predictable behavior in a program riddled with race conditions.
>
> If I'm an implementor reading that statement, I cannot infer any
> concrete requirements about what it is that I'm supposed to do in
> pthread_cond_signal to bring about more predictable scheduling.
>
> Specifications should give specific requirements, not vague opinions.

POSIX *specifies* exactly what scheduling policies a compliant
implementation shall support (SCHED_OTHER, SCHED_FIFO, SCHED_RR, and
SCHED_SPORADIC) and how exactly each of these shall behave.

In addition to specifying the behavior, the spec *explains* the purpose
of some policies so programmers would know when they were meant to be
used. Explanations are there to be helpful, they are not specs. In C++
Standard, they would be formatted as a non-normative Notes.

For example, SCHED_RR, under some conditions, has an effect "to ensure..
that one of them [the threads] does not monopolize the processor". To
me, this is clearly an example of "predictable scheduling behavior".

The spec for pthread_cond_signal and broadast further simply adds one
more condition required to achieve such behavior, namely "the signalling
thread owns the mutex that the waiter threads used to start waiting". If
your doesn't need a predictable scheduling behavior, your app doesn't
have to do that.

For an implementer, this statement is actually very useful: it permits
them to not ensure "predictable scheduling behavior" when the cond
waiter is signaled from a thread not owning the mutex.

Could this statement be thrown away? -- Yes. Would this make
implementor's life easier? -- No, it would make it much harder. The
implementor could be bugged by the user complaints like "Your
implementation must be broken, else why my higher-prio thread is
starving?". With the current spec, they could answer: "This is because
the spec allows my implementation to starve your higher-prio thread to
death -- or exhibit any other unpredictable scheduling behavior -- if
your condvar-signalling thread does not own the mutex that the
higher-prio thread used to start waiting for the condvar".

Re: A Java- / .NET-like monitor

<uj49of$251rr$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.1d4.us!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 06:36:19 +0100
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <uj49of$251rr$1@raubtier-asyl.eternal-september.org>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uinloo$3d813$1@raubtier-asyl.eternal-september.org>
<uio76q$3gj34$1@raubtier-asyl.eternal-september.org>
<uiolf0$3j4r2$3@dont-email.me>
<uipl0g$3su3r$1@raubtier-asyl.eternal-september.org>
<uirdja$7lqi$1@dont-email.me>
<uivd74$15vdk$1@raubtier-asyl.eternal-september.org>
<uive6t$163u2$2@dont-email.me>
<uivgf2$16drp$1@raubtier-asyl.eternal-september.org>
<uivgu9$16cth$1@dont-email.me>
<uivhqg$16kjm$1@raubtier-asyl.eternal-september.org>
<uj0l74$1ch3e$1@dont-email.me>
<uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
<uj398l$1spi2$2@dont-email.me>
<uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>
<uj417p$2436t$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Nov 2023 05:36:15 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="6a95c263ed22598a6a8075ff646bc665";
logging-data="2262907"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/V07OFLZFZHdpQxS+EC+Q09QezMIdDD5M="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:67NNtb3do3ZoMc/JBDt2ViHoIB4=
In-Reply-To: <uj417p$2436t$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Nov 2023 05:36 UTC

Am 16.11.2023 um 04:10 schrieb Chris M. Thomasson:

> Wow... Anyway, where do I add this "!"?

You don't have to change it because the Windows code was correct
anyway.

Re: A Java- / .NET-like monitor

<20231115223459.609@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 06:39:16 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 19
Message-ID: <20231115223459.609@kylheku.com>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad>
<20231112204849.10@kylheku.com> <euB4N.6863$%p%e.3900@fx43.iad>
<20231113192822.953@kylheku.com> <97V4N.19464$Wzw6.11650@fx13.iad>
<uj38lm$1skku$3@dont-email.me> <EAg5N.8455$pgLd.5478@fx05.iad>
Injection-Date: Thu, 16 Nov 2023 06:39:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="0273816523bc6b1f85f67c0e763a6e86";
logging-data="2277364"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yQ/sEqU2fSfh7dJPDOLtWQ+4GYdLJeS0="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:eIgfIA2ZAMGZLCMXT7AR3cevlTU=
 by: Kaz Kylheku - Thu, 16 Nov 2023 06:39 UTC

On 2023-11-16, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
> I am unsure where from that discussion of implementation came. The
> *spec* permits this (signalling without holding the mutex), just warns
> that a predictable scheduling behavior cannot be achieved then.

The spec is supposed to tell implementors what to make.

Loose wording like this is dangerous. An implementor is free to
interpret it like this: whenever a program calls pthread_cond_signal,
and it so happens that the calling threads owns no mutex whatsoever, the
implementation is free to set a flag somewhere, based on which it will
willfully damage the integrity of the scheduling implementation somehow,
so that it behaves like crap.

--
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: A Java- / .NET-like monitor

<uj4pst$27d42$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 11:11:45 +0100
Organization: A noiseless patient Spider
Lines: 81
Message-ID: <uj4pst$27d42$1@raubtier-asyl.eternal-september.org>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad>
<20231112204849.10@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Nov 2023 10:11:41 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="6a95c263ed22598a6a8075ff646bc665";
logging-data="2339970"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX193MtosBx6joCRGl+6FUi021lkokvsPOVQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:MV7OULIOGcJbNq6m0KhfuAb0F8c=
Content-Language: de-DE
In-Reply-To: <20231112204849.10@kylheku.com>
 by: Bonita Montero - Thu, 16 Nov 2023 10:11 UTC

Am 13.11.2023 um 05:50 schrieb Kaz Kylheku:

> Because of the situation that the thread which was signaled is
> trying to acquire the mutex, which, stupidly, the signaling thread
> is still holding. So, oops, back it goes into suspended state, and
> we have to context switch to the mutex holder which has to release
> the mutex and then switch to that signaled thread again.

As I've shown with the comparison of my monitor against a C++ mutex
along with a condition variable there are no additional context swit-
ches with that. The number of voluntary context switches is about the
same as with my monitor, which comprehensibly waits for the mutex and
the condition variable in one step.
As the mutex part and the condition variable part are separate there's
no opportunity to implement that the way I did with a SysV semaphore
set. I guess the backing of the mutex and condition variable on Linux
is the glibc-implementation and it uses signals for that as when you
use a pure mutex; with that you can have an aribitrary state combina-
tion to wake up a thread even if the states are managed separately as
with a mutex and a condition variable.

I simulated that with the follwing code:

#include <iostream>
#include <thread>
#include <vector>
#include <pthread.h>
#include <sys/resource.h>

using namespace std;

int main()
{ constexpr size_t ROUNDS = 1'000;
struct state
{
pthread_mutex_t mtx;
pthread_cond_t cv;
} a, b;
auto init = []( state &s )
{
if( pthread_mutex_init( &s.mtx, nullptr )
|| pthread_cond_init( &s.cv, nullptr ) )
terminate();
};
init( a );
init( b );
auto switches = []()
{
rusage ru;
if( getrusage( RUSAGE_THREAD, &ru ) )
terminate();
return ru.ru_nvcsw;

};
atomic_uint64_t sumSwitches( 0 );
auto thr = [&]( state &my, state &yours )
{
uint64_t before = switches();
for( size_t r = ROUNDS; r--; )
if( pthread_mutex_lock( &my.mtx )
|| pthread_cond_wait( &my.cv, &my.mtx )
|| pthread_mutex_unlock( &my.mtx )
|| pthread_mutex_lock( &yours.mtx )
|| pthread_cond_signal( &yours.cv )
|| pthread_mutex_unlock( &yours.mtx ) )
terminate();
sumSwitches.fetch_add( switches() - before, memory_order_relaxed );
};
vector<jthread> threads;
threads.emplace_back( thr, ref( a ), ref( b ) );
threads.emplace_back( thr, ref( b ), ref( a ) );
if( pthread_cond_signal( &a.cv ) )
terminate();
threads.resize( 0 );
cout << sumSwitches << endl;
}

The result is about 2'000 voluntary context switches.
So no need to signal from outside.

Re: A Java- / .NET-like monitor

<gaq5N.25378$cAm7.15892@fx18.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!i2pn.org!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx18.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: A Java- / .NET-like monitor
Newsgroups: comp.lang.c++
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org> <uiv020$148s1$1@raubtier-asyl.eternal-september.org> <uiv050$1462e$1@dont-email.me> <uiv50o$14quu$1@raubtier-asyl.eternal-september.org> <WcM4N.53198$svP4.12968@fx12.iad> <uj04oh$19j9e$1@raubtier-asyl.eternal-september.org> <mZM4N.10239$rx%7.6902@fx47.iad> <uj0l38$1ch3f$1@dont-email.me> <uj1j2q$1kad4$2@raubtier-asyl.eternal-september.org> <uj38g6$1skku$2@dont-email.me> <uj40j0$23vlu$1@raubtier-asyl.eternal-september.org>
Lines: 11
Message-ID: <gaq5N.25378$cAm7.15892@fx18.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 16 Nov 2023 15:02:36 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 16 Nov 2023 15:02:36 GMT
X-Received-Bytes: 1397
 by: Scott Lurndal - Thu, 16 Nov 2023 15:02 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 15.11.2023 um 21:08 schrieb Chris M. Thomasson:
>
>> Are you sure its 100% atomic for use in multi-thread sync algorithms?
>
>If MSVC generates that code it's atomic.

No, if Intel architecture documentation specifies that it is
single-copy atomic, then it is single-copy atomic.

MSVC is just a poor-to-middling C compiler.

Re: A Java- / .NET-like monitor

<uj5ih0$2booh$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 18:12:04 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <uj5ih0$2booh$1@raubtier-asyl.eternal-september.org>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uiv020$148s1$1@raubtier-asyl.eternal-september.org>
<uiv050$1462e$1@dont-email.me>
<uiv50o$14quu$1@raubtier-asyl.eternal-september.org>
<WcM4N.53198$svP4.12968@fx12.iad>
<uj04oh$19j9e$1@raubtier-asyl.eternal-september.org>
<mZM4N.10239$rx%7.6902@fx47.iad> <uj0l38$1ch3f$1@dont-email.me>
<uj1j2q$1kad4$2@raubtier-asyl.eternal-september.org>
<uj38g6$1skku$2@dont-email.me>
<uj40j0$23vlu$1@raubtier-asyl.eternal-september.org>
<gaq5N.25378$cAm7.15892@fx18.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Nov 2023 17:12:00 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="6a95c263ed22598a6a8075ff646bc665";
logging-data="2482961"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18sd2gMztWfGbO7sBszSM4pVkDsbdQvrgQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:sJJLbhvroMHL6HBmGE1uxsdpjgE=
In-Reply-To: <gaq5N.25378$cAm7.15892@fx18.iad>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Nov 2023 17:12 UTC

Am 16.11.2023 um 16:02 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 15.11.2023 um 21:08 schrieb Chris M. Thomasson:
>>
>>> Are you sure its 100% atomic for use in multi-thread sync algorithms?
>>
>> If MSVC generates that code it's atomic.
>
> No, if Intel architecture documentation specifies that it is
> single-copy atomic, then it is single-copy atomic.

MSVC relies for sure on the right behaviour.

> MSVC is just a poor-to-middling C compiler.

MSVC has the strongest C++20-conformance but the weakest optimizer.

Re: A Java- / .NET-like monitor

<_ys5N.12946$ayBd.1996@fx07.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!panix!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx07.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: A Java- / .NET-like monitor
Newsgroups: comp.lang.c++
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org> <uiv50o$14quu$1@raubtier-asyl.eternal-september.org> <WcM4N.53198$svP4.12968@fx12.iad> <uj04oh$19j9e$1@raubtier-asyl.eternal-september.org> <mZM4N.10239$rx%7.6902@fx47.iad> <uj0l38$1ch3f$1@dont-email.me> <uj1j2q$1kad4$2@raubtier-asyl.eternal-september.org> <uj38g6$1skku$2@dont-email.me> <uj40j0$23vlu$1@raubtier-asyl.eternal-september.org> <gaq5N.25378$cAm7.15892@fx18.iad> <uj5ih0$2booh$1@raubtier-asyl.eternal-september.org>
Lines: 26
Message-ID: <_ys5N.12946$ayBd.1996@fx07.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 16 Nov 2023 17:45:30 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 16 Nov 2023 17:45:30 GMT
X-Received-Bytes: 1900
 by: Scott Lurndal - Thu, 16 Nov 2023 17:45 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 16.11.2023 um 16:02 schrieb Scott Lurndal:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>> Am 15.11.2023 um 21:08 schrieb Chris M. Thomasson:
>>>
>>>> Are you sure its 100% atomic for use in multi-thread sync algorithms?
>>>
>>> If MSVC generates that code it's atomic.
>>
>> No, if Intel architecture documentation specifies that it is
>> single-copy atomic, then it is single-copy atomic.
>
>MSVC relies for sure on the right behaviour.

Right. Keep thinking that.

>
>> MSVC is just a poor-to-middling C compiler.
>
>MSVC has the strongest C++20-conformance but the weakest optimizer.

Faint praise, indeed. Nobody other than Herb cares about C++20 conformance.

Most real world C++ code relies on C++11 for portability. Most
of our systems and our customers systems don't even support C++17.

Re: A Java- / .NET-like monitor

<uj6092$2e2ds$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 13:06:42 -0800
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <uj6092$2e2ds$1@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uinloo$3d813$1@raubtier-asyl.eternal-september.org>
<uio76q$3gj34$1@raubtier-asyl.eternal-september.org>
<uiolf0$3j4r2$3@dont-email.me>
<uipl0g$3su3r$1@raubtier-asyl.eternal-september.org>
<uirdja$7lqi$1@dont-email.me>
<uivd74$15vdk$1@raubtier-asyl.eternal-september.org>
<uive6t$163u2$2@dont-email.me>
<uivgf2$16drp$1@raubtier-asyl.eternal-september.org>
<uivgu9$16cth$1@dont-email.me>
<uivhqg$16kjm$1@raubtier-asyl.eternal-september.org>
<uj0l74$1ch3e$1@dont-email.me>
<uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
<uj398l$1spi2$2@dont-email.me>
<uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>
<uj417p$2436t$1@dont-email.me>
<uj49of$251rr$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Nov 2023 21:06:42 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3af96b48525dafea7d7b80955cb07c1c";
logging-data="2558396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+sozuqsPDGVpgl7zrley3xy/4HyxQkvZ4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:BCzJO3VHrpsTn1hOUWhSf9Bdm9o=
Content-Language: en-US
In-Reply-To: <uj49of$251rr$1@raubtier-asyl.eternal-september.org>
 by: Chris M. Thomasson - Thu, 16 Nov 2023 21:06 UTC

On 11/15/2023 9:36 PM, Bonita Montero wrote:
> Am 16.11.2023 um 04:10 schrieb Chris M. Thomasson:
>
>> Wow... Anyway, where do I add this "!"?
>
> You don't have to change it because the Windows code was correct
> anyway.
>

Huh? Do I have to correct your code with that "!" or not?

Re: A Java- / .NET-like monitor

<uj64bl$2e2ds$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Thu, 16 Nov 2023 14:16:21 -0800
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <uj64bl$2e2ds$3@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108100351.347@kylheku.com>
<uigk5o$1nmku$1@raubtier-asyl.eternal-september.org>
<20231108114723.256@kylheku.com>
<uigp4n$1onpc$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com> <E5e4N.6986$Ubzd.3639@fx36.iad>
<uirrhi$9vg5$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Nov 2023 22:16:21 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="3af96b48525dafea7d7b80955cb07c1c";
logging-data="2558396"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+yxR5z2Aij1FHoPkE9Isq9xHrU/O//FVc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:zYR2nERyCbwyyEV7f1J7MY0/NOM=
Content-Language: en-US
In-Reply-To: <uirrhi$9vg5$1@dont-email.me>
 by: Chris M. Thomasson - Thu, 16 Nov 2023 22:16 UTC

On 11/12/2023 4:44 PM, Chris M. Thomasson wrote:
> On 11/12/2023 4:29 PM, Pavel wrote:
>> Kaz Kylheku wrote:
>>> On 2023-11-12, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>>>> No, Java and .net keep holding the mutex while doing a notify().
>>>> That's called a Mesa monitor.
>>>
>>> I don't suspect that is part of Mesa semantics. (It's definitely part of
>>> Hoare semantics.) Do you have a reference?
>> She doesn't. See my citation in response to her post for the reference
>> to the contrary.
>>
>>>
>>> Since under Mesa semantics, threads re-acquire the mutex with fewer
>>> guarantees and must re-test the desired condition, Mesa semantics
>>> supports the more efficient protocol of signaling outside of the
>>> monitor.
>>>
>>> If you're using POSIX mutexes and conditions, you should call
>>> pthread_cond_signal and pthread_cond_broadcast outside of the mutex,
>>> whenever possible.
>> This is recommended against by the standard for the same reason why
>> Java implements Hoare monitor behavior. Citation:
>>
>> "
>> The pthread_cond_broadcast() or pthread_cond_signal() functions may be
>> called by a thread whether or  not  it  currently  owns  the  mutex
>> that threads calling pthread_cond_wait() or pthread_cond_timedwait()
>> have associated with the condition variable during their waits;
>> however, if predictable  scheduling  behavior  is required, then that
>> mutex shall be locked by the thread calling pthread_cond_broadcast()
>> or pthread_cond_signal(). > "
>>
>>>
>>> (In a nutshell, if you're going to be telling some thread(s) to go ahead
>>> and grab a mutex, get the hell out of their way first).
>>>
>>
>
> Basically, if you signal while locked then another waiting thread is
> going to try to acquire the mutex that is already locked by the
> signalling thread, instant contention. However, wait morphing techniques
> can be used to handle this since a mutex and a condvar are very intimate
> with each other anyway. Usually, signalling outside of the mutex is ideal.

Actually, for some damn reason this is making me think about the
pass-the-buck algorithm, iirc, its from SUN.

A signal to a thread means the signaled thread already owns the mutex.

Re: A Java- / .NET-like monitor

<XvA5N.62534$wvv7.58333@fx14.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!weretis.net!feeder6.news.weretis.net!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
Subject: Re: A Java- / .NET-like monitor
Newsgroups: comp.lang.c++
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231108152102.495@kylheku.com>
<uihnei$21tq7$1@raubtier-asyl.eternal-september.org>
<uihnkd$21rae$1@dont-email.me>
<uihnnm$21tq7$5@raubtier-asyl.eternal-september.org>
<uihnup$21rab$4@dont-email.me>
<uihpgl$227kv$1@raubtier-asyl.eternal-september.org>
<nuT3N.20309$wvv7.18517@fx14.iad>
<uipl56$3sugf$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad>
<20231112204849.10@kylheku.com> <euB4N.6863$%p%e.3900@fx43.iad>
<20231113192822.953@kylheku.com> <97V4N.19464$Wzw6.11650@fx13.iad>
<uj38lm$1skku$3@dont-email.me> <EAg5N.8455$pgLd.5478@fx05.iad>
<20231115223459.609@kylheku.com>
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.1
MIME-Version: 1.0
In-Reply-To: <20231115223459.609@kylheku.com>
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Lines: 26
Message-ID: <XvA5N.62534$wvv7.58333@fx14.iad>
X-Complaints-To: https://www.astraweb.com/aup
NNTP-Posting-Date: Fri, 17 Nov 2023 02:48:23 UTC
Date: Thu, 16 Nov 2023 21:48:15 -0500
X-Received-Bytes: 2841
 by: Pavel - Fri, 17 Nov 2023 02:48 UTC

Kaz Kylheku wrote:
> On 2023-11-16, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
>> I am unsure where from that discussion of implementation came. The
>> *spec* permits this (signalling without holding the mutex), just warns
>> that a predictable scheduling behavior cannot be achieved then.
>
> The spec is supposed to tell implementors what to make.
>
> Loose wording like this is dangerous. An implementor is free to
> interpret it like this: whenever a program calls pthread_cond_signal,
> and it so happens that the calling threads owns no mutex whatsoever, the
> implementation is free to set a flag somewhere, based on which it will
> willfully damage the integrity of the scheduling implementation somehow,
> so that it behaves like crap.
>
If your complaint is about "predictable scheduling behavior" not being
defined in the standard, I understand and sympathize. It could be better
defined. When POSIX threads were developed, this was kinda obvious
because RT guys required that and they know what they mean by that
(meaning -- more or less agree). This is not a good excuse for not
spelling it in the standard of course.

See if this old posting of David Butenhof, one of the spec authors may
clarify the concept:

https://austin-group-l.opengroup.narkive.com/lKcmfoRI/predictable-scheduling-behavior-in-pthread-cond-broadcast

Re: A Java- / .NET-like monitor

<uj6vbg$2m26k$1@raubtier-asyl.eternal-september.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Fri, 17 Nov 2023 06:57:08 +0100
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <uj6vbg$2m26k$1@raubtier-asyl.eternal-september.org>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<uinloo$3d813$1@raubtier-asyl.eternal-september.org>
<uio76q$3gj34$1@raubtier-asyl.eternal-september.org>
<uiolf0$3j4r2$3@dont-email.me>
<uipl0g$3su3r$1@raubtier-asyl.eternal-september.org>
<uirdja$7lqi$1@dont-email.me>
<uivd74$15vdk$1@raubtier-asyl.eternal-september.org>
<uive6t$163u2$2@dont-email.me>
<uivgf2$16drp$1@raubtier-asyl.eternal-september.org>
<uivgu9$16cth$1@dont-email.me>
<uivhqg$16kjm$1@raubtier-asyl.eternal-september.org>
<uj0l74$1ch3e$1@dont-email.me>
<uj1ium$1kad4$1@raubtier-asyl.eternal-september.org>
<uj398l$1spi2$2@dont-email.me>
<uj40kb$23vlu$2@raubtier-asyl.eternal-september.org>
<uj417p$2436t$1@dont-email.me>
<uj49of$251rr$1@raubtier-asyl.eternal-september.org>
<uj6092$2e2ds$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Nov 2023 05:57:04 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="e41417b6cf735d042fee3411535cd521";
logging-data="2820308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+uyXqcSG7wyLBQ9ZwBJCoJV6sF6T6iPqQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ihNlTOqHIIWtWhqOMBZGadwSSAo=
Content-Language: de-DE
In-Reply-To: <uj6092$2e2ds$1@dont-email.me>
 by: Bonita Montero - Fri, 17 Nov 2023 05:57 UTC

Am 16.11.2023 um 22:06 schrieb Chris M. Thomasson:

> Huh? Do I have to correct your code with that "!" or not?

Yes, but that was in the #if defined(__unix__) branch.

Re: A Java- / .NET-like monitor

<oxM5N.70257$wvv7.26310@fx14.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx14.iad.POSTED!not-for-mail
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: A Java- / .NET-like monitor
Newsgroups: comp.lang.c++
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org> <20231111205536.387@kylheku.com> <uiq7o0$1thb$1@raubtier-asyl.eternal-september.org> <Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad> <20231112204849.10@kylheku.com> <euB4N.6863$%p%e.3900@fx43.iad> <20231113192822.953@kylheku.com> <97V4N.19464$Wzw6.11650@fx13.iad> <uj38lm$1skku$3@dont-email.me> <EAg5N.8455$pgLd.5478@fx05.iad> <20231115223459.609@kylheku.com> <XvA5N.62534$wvv7.58333@fx14.iad>
Lines: 42
Message-ID: <oxM5N.70257$wvv7.26310@fx14.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 17 Nov 2023 16:29:08 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 17 Nov 2023 16:29:08 GMT
X-Received-Bytes: 3126
 by: Scott Lurndal - Fri, 17 Nov 2023 16:29 UTC

Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:
>Kaz Kylheku wrote:
>> On 2023-11-16, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
>>> I am unsure where from that discussion of implementation came. The
>>> *spec* permits this (signalling without holding the mutex), just warns
>>> that a predictable scheduling behavior cannot be achieved then.
>>
>> The spec is supposed to tell implementors what to make.
>>
>> Loose wording like this is dangerous. An implementor is free to
>> interpret it like this: whenever a program calls pthread_cond_signal,
>> and it so happens that the calling threads owns no mutex whatsoever, the
>> implementation is free to set a flag somewhere, based on which it will
>> willfully damage the integrity of the scheduling implementation somehow,
>> so that it behaves like crap.
>>
>If your complaint is about "predictable scheduling behavior" not being
>defined in the standard, I understand and sympathize. It could be better
>defined. When POSIX threads were developed, this was kinda obvious
>because RT guys required that and they know what they mean by that
>(meaning -- more or less agree). This is not a good excuse for not
>spelling it in the standard of course.
>
>See if this old posting of David Butenhof, one of the spec authors may
>clarify the concept:
>
>https://austin-group-l.opengroup.narkive.com/lKcmfoRI/predictable-scheduling-behavior-in-pthread-cond-broadcast

When David wrote that, multiprocessor systems were still rare and
limited to very expensive systems (e.g. Sequent) (and for the most
part, weren't running real-time code). I was on the X/Open working group for
a few years during that time period, and one of my collegues at
SGI was part of the 1003.4 working group.

thirty years later, pthread_cond_t is heavily used by non-realtime
code, where such priority inversions (usually very transient) don't
matter.

For the number of cases where pthread_cond_t is used in hard
real-time code, the appropriate techniques (i.e. holding the mutex
while signaling the condition) are available.

Re: A Java- / .NET-like monitor

<uj8b1b$2tap5$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder3.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: A Java- / .NET-like monitor
Date: Fri, 17 Nov 2023 10:22:35 -0800
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <uj8b1b$2tap5$1@dont-email.me>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad>
<20231112204849.10@kylheku.com> <euB4N.6863$%p%e.3900@fx43.iad>
<20231113192822.953@kylheku.com> <97V4N.19464$Wzw6.11650@fx13.iad>
<uj38lm$1skku$3@dont-email.me> <EAg5N.8455$pgLd.5478@fx05.iad>
<20231115223459.609@kylheku.com> <XvA5N.62534$wvv7.58333@fx14.iad>
<oxM5N.70257$wvv7.26310@fx14.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Nov 2023 18:22:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e3dfad7c4c93b3524f06016549f1a58c";
logging-data="3058469"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18EvZD00eLuKpJZytDBNA6yYDR22BJNwgo="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ipaGMCuYL45NR/1Q4TQj9tOlhBc=
In-Reply-To: <oxM5N.70257$wvv7.26310@fx14.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 17 Nov 2023 18:22 UTC

On 11/17/2023 8:29 AM, Scott Lurndal wrote:
> Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> writes:
>> Kaz Kylheku wrote:
>>> On 2023-11-16, Pavel <pauldontspamtolk@removeyourself.dontspam.yahoo> wrote:
>>>> I am unsure where from that discussion of implementation came. The
>>>> *spec* permits this (signalling without holding the mutex), just warns
>>>> that a predictable scheduling behavior cannot be achieved then.
>>>
>>> The spec is supposed to tell implementors what to make.
>>>
>>> Loose wording like this is dangerous. An implementor is free to
>>> interpret it like this: whenever a program calls pthread_cond_signal,
>>> and it so happens that the calling threads owns no mutex whatsoever, the
>>> implementation is free to set a flag somewhere, based on which it will
>>> willfully damage the integrity of the scheduling implementation somehow,
>>> so that it behaves like crap.
>>>
>> If your complaint is about "predictable scheduling behavior" not being
>> defined in the standard, I understand and sympathize. It could be better
>> defined. When POSIX threads were developed, this was kinda obvious
>> because RT guys required that and they know what they mean by that
>> (meaning -- more or less agree). This is not a good excuse for not
>> spelling it in the standard of course.
>>
>> See if this old posting of David Butenhof, one of the spec authors may
>> clarify the concept:
>>
>> https://austin-group-l.opengroup.narkive.com/lKcmfoRI/predictable-scheduling-behavior-in-pthread-cond-broadcast
>
> When David wrote that, multiprocessor systems were still rare and
> limited to very expensive systems (e.g. Sequent) (and for the most
> part, weren't running real-time code). I was on the X/Open working group for
> a few years during that time period, and one of my collegues at
> SGI was part of the 1003.4 working group.
>
> thirty years later, pthread_cond_t is heavily used by non-realtime
> code, where such priority inversions (usually very transient) don't
> matter.
>
> For the number of cases where pthread_cond_t is used in hard
> real-time code, the appropriate techniques (i.e. holding the mutex
> while signaling the condition) are available.
>

Exactly. It depends on what the programmer is trying to accomplish.
Signaling inside of a mutex locked region will work regardless of
priority issues, your code will work.

However, _if_ your goal is not real time and/or enforcing some specific
scheduling polity... Then, I would refrain from that as signalling
outside of the mutex is more efficient in this case.

Re: A Java- / .NET-like monitor

<20231117103650.654@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: A Java- / .NET-like monitor
Date: Fri, 17 Nov 2023 18:37:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <20231117103650.654@kylheku.com>
References: <uig7jl$1l4v0$1@raubtier-asyl.eternal-september.org>
<20231111205536.387@kylheku.com>
<uiq7o0$1thb$1@raubtier-asyl.eternal-september.org>
<Pi84N.104$ayBd.46@fx07.iad> <b9e4N.20671$Ee89.15587@fx17.iad>
<20231112204849.10@kylheku.com> <euB4N.6863$%p%e.3900@fx43.iad>
<20231113192822.953@kylheku.com> <97V4N.19464$Wzw6.11650@fx13.iad>
<uj38lm$1skku$3@dont-email.me> <EAg5N.8455$pgLd.5478@fx05.iad>
<20231115223459.609@kylheku.com> <XvA5N.62534$wvv7.58333@fx14.iad>
<oxM5N.70257$wvv7.26310@fx14.iad>
Injection-Date: Fri, 17 Nov 2023 18:37:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d2b01079437de407e09612bf18f7d877";
logging-data="3065439"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Eu8UaiXCKIRrqdoiogJpV96WdPWnFJWU="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:WXdRwvLXirabcJWQsBtF+qn3om4=
 by: Kaz Kylheku - Fri, 17 Nov 2023 18:37 UTC

On 2023-11-17, Scott Lurndal <scott@slp53.sl.home> wrote:
>>https://austin-group-l.opengroup.narkive.com/lKcmfoRI/predictable-scheduling-behavior-in-pthread-cond-broadcast
>
> When David wrote that, multiprocessor systems were still rare and

The referenced discussion appears to be from early 2010; maybe
he was reiterating something from an earlier time?

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


devel / comp.lang.c++ / A Java- / .NET-like monitor

Pages:1234567891011
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor