Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"Only the hypocrite is really rotten to the core." -- Hannah Arendt.


devel / comp.lang.c++ / Re: Run this under Windows and Linux

SubjectAuthor
* Run this under Windows and LinuxBonita Montero
+* Re: Run this under Windows and LinuxChris M. Thomasson
|`* Re: Run this under Windows and LinuxBonita Montero
| +- Re: Run this under Windows and LinuxBranimir Maksimovic
| `* Re: Run this under Windows and LinuxChris M. Thomasson
|  +* Re: Run this under Windows and LinuxBonita Montero
|  |+* Re: Run this under Windows and LinuxBonita Montero
|  ||+* Re: Run this under Windows and LinuxBonita Montero
|  |||`* Re: Run this under Windows and LinuxScott Lurndal
|  ||| `* Re: Run this under Windows and LinuxBonita Montero
|  |||  `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |||   `* Re: Run this under Windows and LinuxBonita Montero
|  |||    `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |||     +* Re: Run this under Windows and LinuxChris M. Thomasson
|  |||     |+- Re: Run this under Windows and LinuxBonita Montero
|  |||     |`* Re: Run this under Windows and LinuxScott Lurndal
|  |||     | +- Re: Run this under Windows and LinuxBonita Montero
|  |||     | `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |||     |  `- Re: Run this under Windows and LinuxChris M. Thomasson
|  |||     `* Re: Run this under Windows and LinuxScott Lurndal
|  |||      +* Re: Run this under Windows and LinuxChris M. Thomasson
|  |||      |`- Re: Run this under Windows and LinuxChris M. Thomasson
|  |||      `* Re: Run this under Windows and LinuxBonita Montero
|  |||       `- Re: Run this under Windows and LinuxChris M. Thomasson
|  ||+* Re: Run this under Windows and LinuxChris M. Thomasson
|  |||`- Re: Run this under Windows and LinuxBonita Montero
|  ||+* Re: Run this under Windows and LinuxKaz Kylheku
|  |||+- Re: Run this under Windows and LinuxChris M. Thomasson
|  |||`- Re: Run this under Windows and LinuxChris M. Thomasson
|  ||`* Re: Run this under Windows and LinuxMichael S
|  || `* Re: Run this under Windows and LinuxBonita Montero
|  ||  `- Re: Run this under Windows and LinuxChris M. Thomasson
|  |`* Re: Run this under Windows and LinuxChris M. Thomasson
|  | `* Re: Run this under Windows and LinuxBonita Montero
|  |  +* Re: Run this under Windows and LinuxScott Lurndal
|  |  |+* Re: Run this under Windows and LinuxDavid Brown
|  |  ||+- Re: Run this under Windows and LinuxBonita Montero
|  |  ||`* Re: Run this under Windows and LinuxChris M. Thomasson
|  |  || `* Re: Run this under Windows and LinuxDavid Brown
|  |  ||  +- Re: Run this under Windows and LinuxChris M. Thomasson
|  |  ||  `- Re: Run this under Windows and LinuxChris M. Thomasson
|  |  |`* Re: Run this under Windows and LinuxBonita Montero
|  |  | `* Re: Run this under Windows and LinuxKaz Kylheku
|  |  |  `* Re: Run this under Windows and LinuxMichael S
|  |  |   `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |  |    `- Re: Run this under Windows and LinuxKaz Kylheku
|  |  `* Re: Run this under Windows and LinuxKaz Kylheku
|  |   `* Re: Run this under Windows and LinuxBonita Montero
|  |    `* Re: Run this under Windows and LinuxKaz Kylheku
|  |     +* Re: Run this under Windows and LinuxBonita Montero
|  |     |`* Re: Run this under Windows and LinuxDavid Brown
|  |     | `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  +* Re: Run this under Windows and LinuxDavid Brown
|  |     |  |`* Re: Run this under Windows and LinuxBonita Montero
|  |     |  | `* Re: Run this under Windows and LinuxDavid Brown
|  |     |  |  `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   +* Re: Run this under Windows and LinuxDavid Brown
|  |     |  |   |+* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   ||+- Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |   ||+- Re: Run this under Windows and LinuxScott Lurndal
|  |     |  |   ||+- Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  |   ||`* Re: Run this under Windows and LinuxDavid Brown
|  |     |  |   || `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   ||  `* Re: Run this under Windows and LinuxDavid Brown
|  |     |  |   ||   `- Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   |+- Re: Run this under Windows and LinuxScott Lurndal
|  |     |  |   |`- Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  |   +* Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |   |`* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   | +* Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |   | |`* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   | | `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   | |  `- Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  |   | `* Re: Run this under Windows and LinuxScott Lurndal
|  |     |  |   |  `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   |   `* Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |   |    `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   |     +* Re: Run this under Windows and LinuxScott Lurndal
|  |     |  |   |     |`- Re: Run this under Windows and LinuxBonita Montero
|  |     |  |   |     `- Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |   `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  |    +- Re: Run this under Windows and LinuxBonita Montero
|  |     |  |    `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |     `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  |      +* Re: Run this under Windows and LinuxBonita Montero
|  |     |  |      |`* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  |      | `* Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |      |  `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  |      |   `- Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |      `- Re: Run this under Windows and LinuxBonita Montero
|  |     |  +* Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |`- Re: Run this under Windows and LinuxDavid Brown
|  |     |  +* Re: Run this under Windows and LinuxScott Lurndal
|  |     |  |+* Re: Run this under Windows and LinuxBonita Montero
|  |     |  ||`* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  || `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  ||  `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  ||   `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  ||    `* Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  ||     `* Re: Run this under Windows and LinuxBonita Montero
|  |     |  ||      +* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  ||      `* Re: Run this under Windows and LinuxKaz Kylheku
|  |     |  |`- Re: Run this under Windows and LinuxChris M. Thomasson
|  |     |  `* Re: Run this under Windows and LinuxChris M. Thomasson
|  |     `- Re: Run this under Windows and LinuxChris M. Thomasson
|  `* Re: Run this under Windows and LinuxBonita Montero
`* Re: Run this under Windows and LinuxBranimir Maksimovic

Pages:1234567
Re: Run this under Windows and Linux

<ui0gbs$29990$3@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Thu, 2 Nov 2023 16:48:15 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <ui0gbs$29990$3@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Nov 2023 15:48:12 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a1d0bc6b346e263d9751a3023e3af7de";
logging-data="2401568"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19mcL8Pg+DmChNLNTnsyriIsMCO/4oBZEY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:h0u1ciotrOnOq20h8bSMnue+VLQ=
In-Reply-To: <20231102083305.904@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Thu, 2 Nov 2023 15:48 UTC

Am 02.11.2023 um 16:37 schrieb Kaz Kylheku:

> Firstly, it doesn't have to be binary to be used as a mutex.

No, but when being used as a mutex its actual maximum value is one.

> A semaphore isn't a mutex because it doesn't incorporate the concept
> of lock ownership.

Thats not dependent on actual implementation but how you consider
the value of the binary semaphore. If it is false it is owned.

Re: Run this under Windows and Linux

<20231102085649.385@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Thu, 2 Nov 2023 16:00:20 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <20231102085649.385@kylheku.com>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me>
Injection-Date: Thu, 2 Nov 2023 16:00:20 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ef9318d42c2ed0d00615b31aed4999a9";
logging-data="2405896"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18TqJsyFZ/2Qp4fz7mz12WrDAkArJQSjVE="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:OsIGgLbI7F5V5wUhs5DYkf02Z+Y=
 by: Kaz Kylheku - Thu, 2 Nov 2023 16:00 UTC

On 2023-11-02, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 02.11.2023 um 16:37 schrieb Kaz Kylheku:
>
>> Firstly, it doesn't have to be binary to be used as a mutex.
>
> No, but when being used as a mutex its actual maximum value is one.
>
>> A semaphore isn't a mutex because it doesn't incorporate the concept
>> of lock ownership.
>
> Thats not dependent on actual implementation but how you consider
> the value of the binary semaphore. If it is false it is owned.

If it is false, it can be understood as representing a locked state.

Locked isn't necessarily owned.

The semaphore does not record the ID of an owner.

In a correct program, a binary semaphore can represent a lock, yet there
can be legitimate situations where a thread which didn't place the lock
releases it.

--
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: Run this under Windows and Linux

<20231102090052.440@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Thu, 2 Nov 2023 16:02:04 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <20231102090052.440@kylheku.com>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <ROO0N.36030$AvZ9.22601@fx35.iad>
<ui0g47$29990$1@dont-email.me>
Injection-Date: Thu, 2 Nov 2023 16:02:04 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="ef9318d42c2ed0d00615b31aed4999a9";
logging-data="2405896"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18p8WYmR/NdjW7dbdZdzHCs5FQfPud4a7A="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:VCDTJ3KVuR+9mC2QPXi2GYhKF8E=
 by: Kaz Kylheku - Thu, 2 Nov 2023 16:02 UTC

On 2023-11-02, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 02.11.2023 um 15:58 schrieb Scott Lurndal:
>
>> No. Each is distinct.
>
> You can initialize a binary semaphore with true and use it
> as a mutex. And a mutex can be realized without a short path
> but just with a binary semaphore in the mentioned way.

You can use a label, if and goto as a while loop.

That doesn't mean if and goto /are/ while.

Speaking of which, I have often mused that sempahores are like the go to
statement of synchronization---which is ironic, given their inventor.

--
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: Run this under Windows and Linux

<ui0ijl$29qan$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Thu, 2 Nov 2023 17:26:32 +0100
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <ui0ijl$29qan$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Nov 2023 16:26:29 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="a1d0bc6b346e263d9751a3023e3af7de";
logging-data="2419031"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+TEOeRBXFf+97nfkpF6Mh9CmCRz1YGEog="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:AqBjm0R/q/14gxSI99OICkNAxHc=
Content-Language: de-DE
In-Reply-To: <20231102085649.385@kylheku.com>
 by: Bonita Montero - Thu, 2 Nov 2023 16:26 UTC

Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:

> Locked isn't necessarily owned.
> The semaphore does not record the ID of an owner.

A non-recursive mutes also doesn't do this. The surrounding
code itself is designed in a way that it behaves like an owner.

Re: Run this under Windows and Linux

<ui0vru$2cie9$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.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: Run this under Windows and Linux
Date: Thu, 2 Nov 2023 13:12:44 -0700
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <ui0vru$2cie9$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <ROO0N.36030$AvZ9.22601@fx35.iad>
<ui0fi4$293il$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 2 Nov 2023 20:12:46 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e09c3719022536ca5fae38660a75e7d7";
logging-data="2509257"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hsw5LF0ytUt/hauGiENLclroEepdZ+3k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:y7g8qrNi1xHg646BpbmB0Nx+IiI=
In-Reply-To: <ui0fi4$293il$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 2 Nov 2023 20:12 UTC

On 11/2/2023 8:34 AM, David Brown wrote:
> On 02/11/2023 15:58, Scott Lurndal wrote:
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>> Am 01.11.2023 um 20:58 schrieb Chris M. Thomasson:
>>>
>>>> The benaphore is a semaphore not a mutex! Fwiw, you can use any
>>>> semaphore as a binary semaphore for use as a mutex. Got it?
>>>
>>> A binary semaphore is also a mutex.
>>
>> No.  Each is distinct.
>>
>> It is correct, however, to say that both provide the same functionality.
>>
>
> Both provide /similar/ functionality, but not necessarily the same.
> Different OS's differ in the details, but it is common for mutexes to
> have priority boosting if a high priority thread is waiting for a mutex
> currently held by a low priority thread.  Such boosting is normally not
> part of the functionality of a binary semaphore.  This makes them very
> distinctly different on such OS's - a mutex is a lock, a semaphore
> (binary or otherwise) is a signalling mechanism.

Right. Basically, any thread/process can increment and/or decrement a
semaphore. This is different than pure mutex logic. Even if the mutex
uses a semaphore under the covers...

>
> (I don't know if Windows makes such a distinction - it's not an OS you
> use when thread or process priority is important.  It is certainly
> common, though not universal, for RTOS's.  And while I don't know the
> details, I'd be surprised if Linux and other *nix's didn't have such a
> distinction.)
>

Re: Run this under Windows and Linux

<ui106j$2cj95$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.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: Run this under Windows and Linux
Date: Thu, 2 Nov 2023 13:18:27 -0700
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ui106j$2cj95$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 2 Nov 2023 20:18:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="e09c3719022536ca5fae38660a75e7d7";
logging-data="2510117"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+eOWw3sm5G1OKDwuJe/BMzF9jJnXwj89c="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:S4Y5BYx/flip2hzJZMX7ZEOD7MA=
Content-Language: en-US
In-Reply-To: <20231102085649.385@kylheku.com>
 by: Chris M. Thomasson - Thu, 2 Nov 2023 20:18 UTC

On 11/2/2023 9:00 AM, Kaz Kylheku wrote:
> On 2023-11-02, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 02.11.2023 um 16:37 schrieb Kaz Kylheku:
>>
>>> Firstly, it doesn't have to be binary to be used as a mutex.
>>
>> No, but when being used as a mutex its actual maximum value is one.
>>
>>> A semaphore isn't a mutex because it doesn't incorporate the concept
>>> of lock ownership.
>>
>> Thats not dependent on actual implementation but how you consider
>> the value of the binary semaphore. If it is false it is owned.
>
> If it is false, it can be understood as representing a locked state.
>
> Locked isn't necessarily owned.
>
> The semaphore does not record the ID of an owner.
>
> In a correct program, a binary semaphore can represent a lock, yet there
> can be legitimate situations where a thread which didn't place the lock
> releases it.
>

True. This makes me think of robust mutexes... ;^)

Re: Run this under Windows and Linux

<ui2djl$2ngpf$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 10:13:25 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <ui2djl$2ngpf$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <ROO0N.36030$AvZ9.22601@fx35.iad>
<ui0fi4$293il$1@dont-email.me> <ui0vru$2cie9$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 09:13:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d67e3c8bde7f5207c90c089ce10a4a2f";
logging-data="2868015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18SntY6SJDvUaHQHVhLv72B9I1u9Y6J0Jw="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:WXOwa98Crk/4WeRCiuXOStNSmpg=
In-Reply-To: <ui0vru$2cie9$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 3 Nov 2023 09:13 UTC

On 02/11/2023 21:12, Chris M. Thomasson wrote:
> On 11/2/2023 8:34 AM, David Brown wrote:
>> On 02/11/2023 15:58, Scott Lurndal wrote:
>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>> Am 01.11.2023 um 20:58 schrieb Chris M. Thomasson:
>>>>
>>>>> The benaphore is a semaphore not a mutex! Fwiw, you can use any
>>>>> semaphore as a binary semaphore for use as a mutex. Got it?
>>>>
>>>> A binary semaphore is also a mutex.
>>>
>>> No.  Each is distinct.
>>>
>>> It is correct, however, to say that both provide the same functionality.
>>>
>>
>> Both provide /similar/ functionality, but not necessarily the same.
>> Different OS's differ in the details, but it is common for mutexes to
>> have priority boosting if a high priority thread is waiting for a
>> mutex currently held by a low priority thread.  Such boosting is
>> normally not part of the functionality of a binary semaphore.  This
>> makes them very distinctly different on such OS's - a mutex is a lock,
>> a semaphore (binary or otherwise) is a signalling mechanism.
>
> Right. Basically, any thread/process can increment and/or decrement a
> semaphore. This is different than pure mutex logic. Even if the mutex
> uses a semaphore under the covers...
>

That's a very different issue - though of course it is an equally
important distinction between mutexes and binary semaphores. (And no, a
mutex cannot be implemented using semaphores if the mutex has protection
against priority inversion, and the semaphore does not.)

>>
>> (I don't know if Windows makes such a distinction - it's not an OS you
>> use when thread or process priority is important.  It is certainly
>> common, though not universal, for RTOS's.  And while I don't know the
>> details, I'd be surprised if Linux and other *nix's didn't have such a
>> distinction.)
>>
>

Re: Run this under Windows and Linux

<ui2do8$2ngpf$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 10:15:52 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <ui2do8$2ngpf$2@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Nov 2023 09:15:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d67e3c8bde7f5207c90c089ce10a4a2f";
logging-data="2868015"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19y92dMgu5ddONL6Q54+wA3MmjQ6AfPZY4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:GnpI65zmI2nZetQR2TUjbR/UPu8=
In-Reply-To: <ui0ijl$29qan$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 3 Nov 2023 09:15 UTC

On 02/11/2023 17:26, Bonita Montero wrote:
> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>
>> Locked isn't necessarily owned.
>> The semaphore does not record the ID of an owner.
>
> A non-recursive mutes also doesn't do this. The surrounding
> code itself is designed in a way that it behaves like an owner.

Mutexes - recursive or non-recursive - /do/ record their owner when the
lock is taken. Only the owner can unlock the mutex again. This is
completely different from semaphores, where by design any thread can
raise or lower the semaphore.

Re: Run this under Windows and Linux

<ui2jik$2of1r$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!nntp.comgw.net!paganini.bofh.team!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 11:55:20 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <ui2jik$2of1r$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 10:55:16 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="44971adbacb780725366e85975821606";
logging-data="2899003"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19bv2UyYtboHCMKacYl+UQeW3MIiVDqJ18="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:CWQkuvI7jDjWJC4mLhl4kUdZ33Q=
Content-Language: de-DE
In-Reply-To: <ui2do8$2ngpf$2@dont-email.me>
 by: Bonita Montero - Fri, 3 Nov 2023 10:55 UTC

Am 03.11.2023 um 10:15 schrieb David Brown:
> On 02/11/2023 17:26, Bonita Montero wrote:
>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>
>>> Locked isn't necessarily owned.
>>> The semaphore does not record the ID of an owner.
>>
>> A non-recursive mutes also doesn't do this. The surrounding
>> code itself is designed in a way that it behaves like an owner.
>
> Mutexes - recursive or non-recursive - /do/ record their owner when the
> lock is taken. ...

Absolutely not. You can take ownership of a mutex in one thread and
release it in another thread. The mentioned benaphore, which is the
basic skeleton for all mutexes, is a good example for that.

Re: Run this under Windows and Linux

<ui2pgj$2pd4h$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 13:36:39 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <ui2pgj$2pd4h$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhu543$1ns97$1@dont-email.me>
<uhu5c9$1nv1h$1@dont-email.me> <qjx0N.50766$f719.9718@fx42.iad>
<uhu7t2$1oeda$1@dont-email.me> <uhuat3$1omhf$7@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Nov 2023 12:36:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="080e5ea4d61a2409bab2c11b4b283d95";
logging-data="2929809"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+32Aa9b+jI+k/Uu+9fgo+zHRcUvTO18H4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:DuUCfQs5+oj5zdAjDH0WtEry294=
In-Reply-To: <uhuat3$1omhf$7@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 3 Nov 2023 12:36 UTC

Am 01.11.2023 um 21:02 schrieb Chris M. Thomasson:

> If you can avoid using a CAS, aka CMPXCHG over on intel, then do it!
> Although, wrt intel, there is a way to use CMPXCHG without looping.

I don't believe that, give me some code-example _here_. The expected
value of a compare exchange might always have been asynchronously
changed, so you need looping every time.

> Think, strong CAS vs weak CAS...

Strong CAS vs. weak CAS only makes a difference of architectures with
LL/SC. With these architectures a CAS may fail although the actual
data corresponds with the expected value because the cacheline might
have been evicted in the meantime. compare_exchange_strong checks for
this case and loops internally, whereas compare_exchange_weak gives a
false result after one try.

Re: Run this under Windows and Linux

<ui2tah$2q17j$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 14:41:37 +0100
Organization: A noiseless patient Spider
Lines: 48
Message-ID: <ui2tah$2q17j$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 13:41:37 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d67e3c8bde7f5207c90c089ce10a4a2f";
logging-data="2950387"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/7L/r6nmO8yfvcUjD0EeMOZ3xWNRPeKwo="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:OKsRlUSO62uNVInd0AhxyFWxqMk=
Content-Language: en-GB
In-Reply-To: <ui2jik$2of1r$1@dont-email.me>
 by: David Brown - Fri, 3 Nov 2023 13:41 UTC

On 03/11/2023 11:55, Bonita Montero wrote:
> Am 03.11.2023 um 10:15 schrieb David Brown:
>> On 02/11/2023 17:26, Bonita Montero wrote:
>>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>>
>>>> Locked isn't necessarily owned.
>>>> The semaphore does not record the ID of an owner.
>>>
>>> A non-recursive mutes also doesn't do this. The surrounding
>>> code itself is designed in a way that it behaves like an owner.
>>
>> Mutexes - recursive or non-recursive - /do/ record their owner when
>> the lock is taken. ...
>
> Absolutely not. You can take ownership of a mutex in one thread and
> release it in another thread. The mentioned benaphore, which is the
> basic skeleton for all mutexes, is a good example for that.
>

You can call that a mutex if you like, but you'd be wrong. You could
call it a banana, and you would do no worse.

Wikipedia may not be have any particular authority on its definitions,
but it explains the difference between mutexes and semaphores quite well:

<https://en.wikipedia.org/wiki/Lock_(computer_science)#Mutexes_vs._semaphores>

Critical to the point of a mutex is that only the thread that locks it
can unlock it.

You can look at the notes for C++ semaphores here, which make the
distinction clear:

<https://en.cppreference.com/w/cpp/thread/counting_semaphore>

Documentation for C++ mutexes is here :

<https://en.cppreference.com/w/cpp/thread/mutex>
<https://en.cppreference.com/w/cpp/thread/mutex/unlock>

Or you can read the C++ standards if you prefer. (I find the
cppreference pages much easier to follow.)

Or you can look up the documentation for Windows mutexes on MS's webpages.

Re: Run this under Windows and Linux

<20231103160428.00007936@yahoo.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: already5...@yahoo.com (Michael S)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 16:04:28 +0200
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <20231103160428.00007936@yahoo.com>
References: <uhnl0h$bm9a$1@dont-email.me>
<uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me>
<uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me>
<uhu543$1ns97$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="f37f59f01cd7949520c880da2f80c3fe";
logging-data="2952106"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Xr9H3HHlKjzglxg6uOb7VoQDDmNfQW54="
Cancel-Lock: sha1:6tMHtGXzdeBX5L+L3luEakl97Ak=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)
 by: Michael S - Fri, 3 Nov 2023 14:04 UTC

On Wed, 1 Nov 2023 19:24:06 +0100
Bonita Montero <Bonita.Montero@gmail.com> wrote:

> Am 01.11.2023 um 13:00 schrieb Bonita Montero:
>
> > I guess he wouldn't have given the benaphore its name because its
> > the simplest form of a mutex and you can find for sure a lot of
> > similar implementations of that on the net.
>
> I found that the name benaphore was given 1996. Maybe this was the
> first time this idea was published. But this idea is that obvious
> that I had it myself that I think there were several people which
> also had this idea before 1996. A hint on how soon this has been
> invented may be the introduction of the LOCK XADD instruction which
> makes this kind of mutex implementable more efficient than with
> LOCK CMPXCHG because this operation never fails.
>

Semophores can be efficiently implemented on "old" x86 by means of
'LOCK ADD mem, reg'. It is possible due to arithmetic flags generated
by ADD instructiion. As far as semaphores goes 'LOCK XADD' adds little
or nothing to efficiency over 'LOCK ADD'. XADD is just easier to use as
an intrinsic from C or similar languages.

Re: Run this under Windows and Linux

<20231103161010.0000527b@yahoo.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: already5...@yahoo.com (Michael S)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 16:10:10 +0200
Organization: A noiseless patient Spider
Lines: 24
Message-ID: <20231103161010.0000527b@yahoo.com>
References: <uhnl0h$bm9a$1@dont-email.me>
<uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me>
<uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me>
<uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me>
<ROO0N.36030$AvZ9.22601@fx35.iad>
<ui0g47$29990$1@dont-email.me>
<20231102090052.440@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Injection-Info: dont-email.me; posting-host="f37f59f01cd7949520c880da2f80c3fe";
logging-data="2952106"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nrXPf2h30Sh8BoiebcuMvcU0uEzDvJjQ="
Cancel-Lock: sha1:1WZWqTOq+J2g76Pgwy5T/6XoLYU=
X-Newsreader: Claws Mail 4.1.1 (GTK 3.24.34; x86_64-w64-mingw32)
 by: Michael S - Fri, 3 Nov 2023 14:10 UTC

On Thu, 2 Nov 2023 16:02:04 -0000 (UTC)
Kaz Kylheku <864-117-4973@kylheku.com> wrote:

> On 2023-11-02, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> > Am 02.11.2023 um 15:58 schrieb Scott Lurndal:
> >
> >> No. Each is distinct.
> >
> > You can initialize a binary semaphore with true and use it
> > as a mutex. And a mutex can be realized without a short path
> > but just with a binary semaphore in the mentioned way.
>
> You can use a label, if and goto as a while loop.
>
> That doesn't mean if and goto /are/ while.
>
> Speaking of which, I have often mused that sempahores are like the go
> to statement of synchronization---which is ironic, given their
> inventor.
>

IMHO, the word 'mutex' has no exact meaning agreed by all or even
majority of Computer Science community.

Re: Run this under Windows and Linux

<ui2vnl$2qcrs$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 15:22:49 +0100
Organization: A noiseless patient Spider
Lines: 47
Message-ID: <ui2vnl$2qcrs$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <ui2tah$2q17j$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 14:22:45 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="080e5ea4d61a2409bab2c11b4b283d95";
logging-data="2962300"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/80yWI/jASiPLLBW8LCEixt5r95pUWP6Y="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:ZjYyip3U/YhjH13MajEE+2dlphI=
Content-Language: de-DE
In-Reply-To: <ui2tah$2q17j$1@dont-email.me>
 by: Bonita Montero - Fri, 3 Nov 2023 14:22 UTC

Am 03.11.2023 um 14:41 schrieb David Brown:
> On 03/11/2023 11:55, Bonita Montero wrote:
>> Am 03.11.2023 um 10:15 schrieb David Brown:
>>> On 02/11/2023 17:26, Bonita Montero wrote:
>>>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>>>
>>>>> Locked isn't necessarily owned.
>>>>> The semaphore does not record the ID of an owner.
>>>>
>>>> A non-recursive mutes also doesn't do this. The surrounding
>>>> code itself is designed in a way that it behaves like an owner.
>>>
>>> Mutexes - recursive or non-recursive - /do/ record their owner when
>>> the lock is taken. ...
>>
>> Absolutely not. You can take ownership of a mutex in one thread and
>> release it in another thread. The mentioned benaphore, which is the
>> basic skeleton for all mutexes, is a good example for that.
>>
>
> You can call that a mutex if you like, but you'd be wrong.  You could
> call it a banana, and you would do no worse.
> Wikipedia may not be have any particular authority on its definitions,
> but it explains the difference between mutexes and semaphores quite well:
> <https://en.wikipedia.org/wiki/Lock_(computer_science)#Mutexes_vs._semaphores>
> Critical to the point of a mutex is that only the thread that locks it
> can unlock it.
> You can look at the notes for C++ semaphores here, which make the
> distinction clear:

At this point in the thread I was discussion whether a mutex has the
notion of an ownership and it mutexes vs. semaphores.

>
> <https://en.cppreference.com/w/cpp/thread/counting_semaphore>
>
> Documentation for C++ mutexes is here :
>
> <https://en.cppreference.com/w/cpp/thread/mutex>
> <https://en.cppreference.com/w/cpp/thread/mutex/unlock>
>
> Or you can read the C++ standards if you prefer.  (I find the
> cppreference pages much easier to follow.)
>
> Or you can look up the documentation for Windows mutexes on MS's webpages.
>

Re: Run this under Windows and Linux

<ui2vqr$2qcrs$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.hispagatos.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 15:24:31 +0100
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <ui2vqr$2qcrs$2@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhu543$1ns97$1@dont-email.me>
<20231103160428.00007936@yahoo.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Nov 2023 14:24:27 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="080e5ea4d61a2409bab2c11b4b283d95";
logging-data="2962300"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18h0Qxhpvh0zKN/tsoLog6Fv4A2LzP23aY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:k4mGotIwvwiyxHrmvNzeGZpJuRw=
In-Reply-To: <20231103160428.00007936@yahoo.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 3 Nov 2023 14:24 UTC

Am 03.11.2023 um 15:04 schrieb Michael S:

> Semophores can be efficiently implemented on "old" x86 by means of
> 'LOCK ADD mem, reg'. ...

Semaphores need much more code and this code is usually in the kernel
since with a semaphore a thread may go to sleep or be awakened.

Re: Run this under Windows and Linux

<20231103082409.123@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 15:32:38 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <20231103082409.123@kylheku.com>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 15:32:38 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2e148673ec60bf6f5c0bc2f39a587be1";
logging-data="2979678"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+ugghhtHPkhlkM6rh/8gx9ev/8nOg10Og="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:+99hbGTljJZf7iks9jyu8+1L6dI=
 by: Kaz Kylheku - Fri, 3 Nov 2023 15:32 UTC

On 2023-11-03, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 03.11.2023 um 10:15 schrieb David Brown:
>> On 02/11/2023 17:26, Bonita Montero wrote:
>>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>>
>>>> Locked isn't necessarily owned.
>>>> The semaphore does not record the ID of an owner.
>>>
>>> A non-recursive mutes also doesn't do this. The surrounding
>>> code itself is designed in a way that it behaves like an owner.
>>
>> Mutexes - recursive or non-recursive - /do/ record their owner when the
>> lock is taken. ...
>
> Absolutely not. You can take ownership of a mutex in one thread and
> release it in another thread.

Not POSIX mutexes: pthread_mutex_unlock by a non-owner is either
undefined behavior, or a condition diagnosed by an error return value,
depending on the mutex attributes:

See the table here:

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

E.g. for a norma mutex type which is not attributed as robust,
it is undefined behavior.

Support for unlocking by a non-owner is possible in a mutex, but that's
a non-mutex-like behavioral extension.

A mutex that is owned by a process, rather than a thread, can be locked
by one thread and unlocked by another. Classic POSIX file locks (F_SETLK
code of fcntl, etc) are like this, IIRC. That's still mutex-like, just
the scope is process, rather than thread.

--
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: Run this under Windows and Linux

<ui340b$2r25r$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 16:35:39 +0100
Organization: A noiseless patient Spider
Lines: 62
Message-ID: <ui340b$2r25r$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <ui2tah$2q17j$1@dont-email.me>
<ui2vnl$2qcrs$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 15:35:39 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d67e3c8bde7f5207c90c089ce10a4a2f";
logging-data="2984123"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+RurY8D10KwgdgJzkQIv8z1lH6brFzqI8="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:Ht2CfgaghS33qfDHvxjQ14jpCdg=
In-Reply-To: <ui2vnl$2qcrs$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 3 Nov 2023 15:35 UTC

On 03/11/2023 15:22, Bonita Montero wrote:
> Am 03.11.2023 um 14:41 schrieb David Brown:
>> On 03/11/2023 11:55, Bonita Montero wrote:
>>> Am 03.11.2023 um 10:15 schrieb David Brown:
>>>> On 02/11/2023 17:26, Bonita Montero wrote:
>>>>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>>>>
>>>>>> Locked isn't necessarily owned.
>>>>>> The semaphore does not record the ID of an owner.
>>>>>
>>>>> A non-recursive mutes also doesn't do this. The surrounding
>>>>> code itself is designed in a way that it behaves like an owner.
>>>>
>>>> Mutexes - recursive or non-recursive - /do/ record their owner when
>>>> the lock is taken. ...
>>>
>>> Absolutely not. You can take ownership of a mutex in one thread and
>>> release it in another thread. The mentioned benaphore, which is the
>>> basic skeleton for all mutexes, is a good example for that.
>>>
>>
>> You can call that a mutex if you like, but you'd be wrong.  You could
>> call it a banana, and you would do no worse.
>> Wikipedia may not be have any particular authority on its definitions,
>> but it explains the difference between mutexes and semaphores quite well:
>> <https://en.wikipedia.org/wiki/Lock_(computer_science)#Mutexes_vs._semaphores>
>> Critical to the point of a mutex is that only the thread that locks it
>> can unlock it.
>> You can look at the notes for C++ semaphores here, which make the
>> distinction clear:
>
> At this point in the thread I was discussion whether a mutex has the
> notion of an ownership and it mutexes vs. semaphores.
>

And using the definitions held by most people involved (including the
C++ standard library, the Windows API, and AFAIK POSIX), mutexes have
ownership and semaphores do not. A semaphore is not a lock, it is a
signalling mechanism - and any thread can signal it up or down. A mutex
is a locking mechanism to ensure mutually exclusive access to some
resource, and only the owner can release the lock (baring exceptional
circumstances, such as a process being killed by the OS). A sort-of
mutex where any thread could release the lock would be as useful as a
chocolate teapot - as would a semaphore which could only be lowered by
the thread that raised it.

>>
>> <https://en.cppreference.com/w/cpp/thread/counting_semaphore>
>>
>> Documentation for C++ mutexes is here :
>>
>> <https://en.cppreference.com/w/cpp/thread/mutex>
>> <https://en.cppreference.com/w/cpp/thread/mutex/unlock>
>>
>> Or you can read the C++ standards if you prefer.  (I find the
>> cppreference pages much easier to follow.)
>>
>> Or you can look up the documentation for Windows mutexes on MS's
>> webpages.
>>
>

Re: Run this under Windows and Linux

<ui34r0$2r7cc$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 16:49:56 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <ui34r0$2r7cc$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <ui2tah$2q17j$1@dont-email.me>
<ui2vnl$2qcrs$1@dont-email.me> <ui340b$2r25r$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Nov 2023 15:49:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="080e5ea4d61a2409bab2c11b4b283d95";
logging-data="2989452"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18w8O6DCGDf4h8DQWRDxl/I/ijnxuHFexg="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xXTyCwvr+20aMjBGUTi0kD2hAsw=
In-Reply-To: <ui340b$2r25r$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 3 Nov 2023 15:49 UTC

Am 03.11.2023 um 16:35 schrieb David Brown:

> And using the definitions held by most people involved (including the
> C++ standard library, the Windows API, and AFAIK POSIX), mutexes have
> ownership and semaphores do not. ...

Mutexes only have ownership if they're recursive. Otherwise you
can easily unlock a mutex which was locked in another thread.

> A semaphore is not a lock, ...

It can be used as a lock although it is not recommended because
a semaphore is usually a pure kernel facility.

Re: Run this under Windows and Linux

<kA91N.279085$8fO.263728@fx15.iad>

  copy mid

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

  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!fx15.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: Run this under Windows and Linux
Newsgroups: comp.lang.c++
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me> <uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me> <uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me> <uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com> <ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com> <ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me> <ui2jik$2of1r$1@dont-email.me>
Lines: 18
Message-ID: <kA91N.279085$8fO.263728@fx15.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 03 Nov 2023 16:53:36 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 03 Nov 2023 16:53:36 GMT
X-Received-Bytes: 1640
 by: Scott Lurndal - Fri, 3 Nov 2023 16:53 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 03.11.2023 um 10:15 schrieb David Brown:
>> On 02/11/2023 17:26, Bonita Montero wrote:
>>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>>
>>>> Locked isn't necessarily owned.
>>>> The semaphore does not record the ID of an owner.
>>>
>>> A non-recursive mutes also doesn't do this. The surrounding
>>> code itself is designed in a way that it behaves like an owner.
>>
>> Mutexes - recursive or non-recursive - /do/ record their owner when the
>> lock is taken. ...
>
>Absolutely not. You can take ownership of a mutex in one thread and
>release it in another thread.

That has to be the worst idea you've proposed so far.

Re: Run this under Windows and Linux

<ui393f$2s0sv$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!rocksolid2!news.neodome.net!news.mixmin.net!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 18:02:39 +0100
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <ui393f$2s0sv$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <ui2tah$2q17j$1@dont-email.me>
<ui2vnl$2qcrs$1@dont-email.me> <ui340b$2r25r$1@dont-email.me>
<ui34r0$2r7cc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 3 Nov 2023 17:02:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d67e3c8bde7f5207c90c089ce10a4a2f";
logging-data="3015583"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/1IzxDKKEK29GMFFq7a4qqUOe3Dulti3Y="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:nZ6KCcuxKWRVpBu/cyAnYdRTt2Q=
In-Reply-To: <ui34r0$2r7cc$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Fri, 3 Nov 2023 17:02 UTC

On 03/11/2023 16:49, Bonita Montero wrote:
> Am 03.11.2023 um 16:35 schrieb David Brown:
>
>> And using the definitions held by most people involved (including the
>> C++ standard library, the Windows API, and AFAIK POSIX), mutexes have
>> ownership and semaphores do not. ...
>
> Mutexes only have ownership if they're recursive. Otherwise you
> can easily unlock a mutex which was locked in another thread.
>

Please read <https://en.cppreference.com/w/cpp/thread/mutex/unlock>.
Note the sentence "The mutex must be locked by the current thread of
execution, otherwise, the behavior is undefined."

Please read the C++ standards, section [thread.mutex.requirements.mutex]
and note that for "unlock()", there is the sentence "Preconditions: The
calling thread owns the mutex."

Please learn what "undefined behaviour" means, and what "preconditions"
mean.

Then come back and apologise.

>> A semaphore is not a lock, ...
>
> It can be used as a lock although it is not recommended because
> a semaphore is usually a pure kernel facility.
>

Using a semaphore as a lock is not recommended because a semaphore does
not make a good lock. A main reason for that is that it has no concept
of ownership. /All/ locking and inter-thread signalling mechanisms rely
on kernel facilities, because they need to be able to sleep, and to wake
sleeping threads.

Re: Run this under Windows and Linux

<ui399g$2s0sv$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 18:05:52 +0100
Organization: A noiseless patient Spider
Lines: 43
Message-ID: <ui399g$2s0sv$2@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <20231103082409.123@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 17:05:52 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="d67e3c8bde7f5207c90c089ce10a4a2f";
logging-data="3015583"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nM2+Llg5N+amHruIH4TBayKhY2NPVyEQ="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.11.0
Cancel-Lock: sha1:jS5utkf+yFvThahAJSXmV2D27y8=
In-Reply-To: <20231103082409.123@kylheku.com>
Content-Language: en-GB
 by: David Brown - Fri, 3 Nov 2023 17:05 UTC

On 03/11/2023 16:32, Kaz Kylheku wrote:
> On 2023-11-03, Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 03.11.2023 um 10:15 schrieb David Brown:
>>> On 02/11/2023 17:26, Bonita Montero wrote:
>>>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>>>
>>>>> Locked isn't necessarily owned.
>>>>> The semaphore does not record the ID of an owner.
>>>>
>>>> A non-recursive mutes also doesn't do this. The surrounding
>>>> code itself is designed in a way that it behaves like an owner.
>>>
>>> Mutexes - recursive or non-recursive - /do/ record their owner when the
>>> lock is taken. ...
>>
>> Absolutely not. You can take ownership of a mutex in one thread and
>> release it in another thread.
>
> Not POSIX mutexes: pthread_mutex_unlock by a non-owner is either
> undefined behavior, or a condition diagnosed by an error return value,
> depending on the mutex attributes:
>
> See the table here:
>
> https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_mutex_lock.html
>
> E.g. for a norma mutex type which is not attributed as robust,
> it is undefined behavior.
>
> Support for unlocking by a non-owner is possible in a mutex, but that's
> a non-mutex-like behavioral extension.
>
> A mutex that is owned by a process, rather than a thread, can be locked
> by one thread and unlocked by another. Classic POSIX file locks (F_SETLK
> code of fcntl, etc) are like this, IIRC. That's still mutex-like, just
> the scope is process, rather than thread.
>

Mutexes are locks, but not all locks are mutexes. File locks are not
mutexes - they are for controlling access to files, and it might
(rarely) make sense to unlock them from a different thread than the
locking thread.

Re: Run this under Windows and Linux

<ui39dr$2s28j$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 18:08:15 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <ui39dr$2s28j$1@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <ui2tah$2q17j$1@dont-email.me>
<ui2vnl$2qcrs$1@dont-email.me> <ui340b$2r25r$1@dont-email.me>
<ui34r0$2r7cc$1@dont-email.me> <ui393f$2s0sv$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 17:08:11 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="080e5ea4d61a2409bab2c11b4b283d95";
logging-data="3016979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+YZtTUtsoGmsi+7K6PHSOIk8XbNzQc/Bk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:6wY/UvioKLF+bVNsWWaL61Mee9U=
Content-Language: de-DE
In-Reply-To: <ui393f$2s0sv$1@dont-email.me>
 by: Bonita Montero - Fri, 3 Nov 2023 17:08 UTC

Am 03.11.2023 um 18:02 schrieb David Brown:

> Please read <https://en.cppreference.com/w/cpp/thread/mutex/unlock>.
> Note the sentence "The mutex must be locked by the current thread of
> execution, otherwise, the behavior is undefined."

Maybe, but I'm talking about how mutexes usually work internally.

> Using a semaphore as a lock is not recommended because a semaphore does
> not make a good lock.  A main reason for that is that it has no concept
> of ownership. ...

Mutexes also usually have no notion of ownership.

Re: Run this under Windows and Linux

<ui39gf$2s28j$2@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 18:09:39 +0100
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <ui39gf$2s28j$2@dont-email.me>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <kA91N.279085$8fO.263728@fx15.iad>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 3 Nov 2023 17:09:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="080e5ea4d61a2409bab2c11b4b283d95";
logging-data="3016979"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX186XpRwwL5nYCiwdsaH3Y5qSmszUJzZT9k="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:lLdIk8exlQNc0OD94thnUx33BD0=
In-Reply-To: <kA91N.279085$8fO.263728@fx15.iad>
Content-Language: de-DE
 by: Bonita Montero - Fri, 3 Nov 2023 17:09 UTC

Am 03.11.2023 um 17:53 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 03.11.2023 um 10:15 schrieb David Brown:
>>> On 02/11/2023 17:26, Bonita Montero wrote:
>>>> Am 02.11.2023 um 17:00 schrieb Kaz Kylheku:
>>>>
>>>>> Locked isn't necessarily owned.
>>>>> The semaphore does not record the ID of an owner.
>>>>
>>>> A non-recursive mutes also doesn't do this. The surrounding
>>>> code itself is designed in a way that it behaves like an owner.
>>>
>>> Mutexes - recursive or non-recursive - /do/ record their owner when the
>>> lock is taken. ...
>>
>> Absolutely not. You can take ownership of a mutex in one thread and
>> release it in another thread.
>
> That has to be the worst idea you've proposed so far.

I won't say that this is recommendable but just that it is possible
from the way how a mutex usually works. I just wanted to say with
that that mutexes usually have no ownership. You can see that with
the benapohre.

Re: Run this under Windows and Linux

<20231103102128.731@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 17:28:51 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <20231103102128.731@kylheku.com>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <ui2tah$2q17j$1@dont-email.me>
<ui2vnl$2qcrs$1@dont-email.me> <ui340b$2r25r$1@dont-email.me>
<ui34r0$2r7cc$1@dont-email.me>
Injection-Date: Fri, 3 Nov 2023 17:28:51 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2e148673ec60bf6f5c0bc2f39a587be1";
logging-data="3020305"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JTXm6iz7WiU41DG+3Khihg7e9l7gzBgo="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:SC6tIJ5y7XlMw6ZboOOfbfZwUS0=
 by: Kaz Kylheku - Fri, 3 Nov 2023 17:28 UTC

On 2023-11-03, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 03.11.2023 um 16:35 schrieb David Brown:
>
>> And using the definitions held by most people involved (including the
>> C++ standard library, the Windows API, and AFAIK POSIX), mutexes have
>> ownership and semaphores do not. ...
>
> Mutexes only have ownership if they're recursive. Otherwise you
> can easily unlock a mutex which was locked in another thread.

That depends entirely on which kind of mutex on what platform.

- POSIX mutexes make that either an error, or undefined behavior,
depending on the mutex attributes.

- MSDN says this about critical sections: "If a thread calls
LeaveCriticalSection when it does not have ownership of the specified
critical section object, an error occurs that may cause another thread
using EnterCriticalSection to wait indefinitely."

- MSDN, again, about Win32 mutex objects: "The ReleaseMutex function
fails if the calling thread does not own the mutex object."

- ISO C (since C11) mtx_unlock: undefined behavior if mutex is not
locked by the calling thread.

- C++ std::mutex::unlock: ditto.

At this point, I'm already well into stuff I don't give a shit about,
to look for more. I don't care if ScrotelyOS developed in Ruritania
between 1973 and 1981 had "mutexes" that had up to three owners.

--
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: Run this under Windows and Linux

<20231103102914.506@kylheku.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder2.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 864-117-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Run this under Windows and Linux
Date: Fri, 3 Nov 2023 17:29:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <20231103102914.506@kylheku.com>
References: <uhnl0h$bm9a$1@dont-email.me> <uhp2gk$jvlg$1@dont-email.me>
<uhqrnb$11io0$1@dont-email.me> <uhrprb$175ve$1@dont-email.me>
<uhtekk$1jn05$1@dont-email.me> <uhual7$1omhf$4@dont-email.me>
<uhveha$22bbn$2@dont-email.me> <20231102083305.904@kylheku.com>
<ui0gbs$29990$3@dont-email.me> <20231102085649.385@kylheku.com>
<ui0ijl$29qan$1@dont-email.me> <ui2do8$2ngpf$2@dont-email.me>
<ui2jik$2of1r$1@dont-email.me> <ui2tah$2q17j$1@dont-email.me>
<ui2vnl$2qcrs$1@dont-email.me> <ui340b$2r25r$1@dont-email.me>
<ui34r0$2r7cc$1@dont-email.me> <ui393f$2s0sv$1@dont-email.me>
<ui39dr$2s28j$1@dont-email.me>
Injection-Date: Fri, 3 Nov 2023 17:29:40 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="2e148673ec60bf6f5c0bc2f39a587be1";
logging-data="3020305"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kr6pHIwXrebQAlYxfoyyq6lLXIz9jcOk="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:iLEASE22eBb7COX0CsIX9uJA3vU=
 by: Kaz Kylheku - Fri, 3 Nov 2023 17:29 UTC

On 2023-11-03, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 03.11.2023 um 18:02 schrieb David Brown:
>
>> Please read <https://en.cppreference.com/w/cpp/thread/mutex/unlock>.
>> Note the sentence "The mutex must be locked by the current thread of
>> execution, otherwise, the behavior is undefined."
>
> Maybe, but I'm talking about how mutexes usually work internally.

"Never mind that a[i++] = i is undefined; I'm talking about how it
works internally, damn it!!!"

--
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++ / Re: Run this under Windows and Linux

Pages:1234567
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor