Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Life would be so much easier if we could just look at the source code. -- Dave Olson


devel / comp.unix.programmer / Re: Whats the point of pthread_cond_broadcast() ?

SubjectAuthor
* Whats the point of pthread_cond_broadcast() ?Muttley
+* Whats the point of pthread_cond_broadcast() ?Nicolas George
|`* Whats the point of pthread_cond_broadcast() ?Muttley
| `* Whats the point of pthread_cond_broadcast() ?Nicolas George
|  `- Whats the point of pthread_cond_broadcast() ?Muttley
+* Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
|`* Whats the point of pthread_cond_broadcast() ?Kaz Kylheku
| `- Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
+* Whats the point of pthread_cond_broadcast() ?Kaz Kylheku
|`* Whats the point of pthread_cond_broadcast() ?Muttley
| `* Whats the point of pthread_cond_broadcast() ?Nicolas George
|  +* Whats the point of pthread_cond_broadcast() ?Muttley
|  |`- Whats the point of pthread_cond_broadcast() ?Nicolas George
|  `- Whats the point of pthread_cond_broadcast() ?Kaz Kylheku
`* Whats the point of pthread_cond_broadcast() ?Gary R. Schmidt
 `* Whats the point of pthread_cond_broadcast() ?Muttley
  +* Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |`* Whats the point of pthread_cond_broadcast() ?Muttley
  | +* Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  | |`- Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  | `* Whats the point of pthread_cond_broadcast() ?Kaz Kylheku
  |  +* Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  |  |`* Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |  | `- Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  |  `* Whats the point of pthread_cond_broadcast() ?Muttley
  |   `* Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  |    `* Whats the point of pthread_cond_broadcast() ?Muttley
  |     +* Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |     |`* Whats the point of pthread_cond_broadcast() ?Muttley
  |     | +* Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |     | |`* Whats the point of pthread_cond_broadcast() ?Muttley
  |     | | `* Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |     | |  +* Whats the point of pthread_cond_broadcast() ?Muttley
  |     | |  |`* Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  |     | |  | `* Whats the point of pthread_cond_broadcast() ?Muttley
  |     | |  |  +* Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |     | |  |  |`* Whats the point of pthread_cond_broadcast() ?Muttley
  |     | |  |  | `- Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  |     | |  |  `- Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  |     | |  `* Whats the point of pthread_cond_broadcast() ?Nicolas George
  |     | |   `* Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |     | |    `* Whats the point of pthread_cond_broadcast() ?Muttley
  |     | |     `- Whats the point of pthread_cond_broadcast() ?Scott Lurndal
  |     | `- Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  |     `- Whats the point of pthread_cond_broadcast() ?Rainer Weikusat
  `* Whats the point of pthread_cond_broadcast() ?Kaz Kylheku
   `- Whats the point of pthread_cond_broadcast() ?Muttley

Pages:12
Re: Whats the point of pthread_cond_broadcast() ?

<trvpa4$46dr$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10714&group=comp.unix.programmer#10714

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 8 Feb 2023 09:16:52 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <trvpa4$46dr$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me>
<20230207105619.740@kylheku.com>
Injection-Date: Wed, 8 Feb 2023 09:16:52 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="adf850dd2e53d5513311e94b23b46a24";
logging-data="137659"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+EJwgwbO/Bq0pmS1/cBtdX"
Cancel-Lock: sha1:gqRjeCgEOF18OyCquLcH8qkZzu8=
 by: Mutt...@dastardlyhq.com - Wed, 8 Feb 2023 09:16 UTC

On Tue, 7 Feb 2023 19:04:59 -0000 (UTC)
Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>On 2023-02-07, Muttley@dastardlyhq.com <Muttley@dastardlyhq.com> wrote:
>> Yes, that is the official position and in the OS kernel all the threads
>> may well get woken up. However from the application program POV there's no
>> difference because only 1 thread exits pthread_cond_wait() per signal or
>> broadcast sent.
>
>That is simply false. It's true that only one waiting thread at a time
>can exit from the function. But that's because of the mutex.

Err yes, and you can't use condition variables without a mutex so I'm not
sure what your point is.

>If you broadcast the condition, all threads waiting on the condition
>will wake up and contend for the mutex.

I know. And? How does that change the functionality from the POV of the
application code?

>Threads contenting for the mutex proceed when the mutex is available.
>
>Threads sleeping on the condition variable do not proceed regardless
>of what is happening with the mutex.

That makes no sense. Either a thread is waiting in pthread_cond_wait() or it
isn't. If it isn't then its irrelevant to this discussion.

>> If multiple threads exited the wait then that would be a useful paradigm
>> but AFAIK pthreads doesn't supply that functionality.
>
>Yes it does! If you need the paradigm of multiple threads being
>woken up together without having to pass serially through a mutex,
>POSIX provides barriers: pthread_barrier_wait.

Ok, didn't know about that. However it appears to be optional not mandatory
and MacOS doesn't support it so not much use for truly portable code.

Re: Whats the point of pthread_cond_broadcast() ?

<trvpl0$48dj$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10715&group=comp.unix.programmer#10715

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 8 Feb 2023 09:22:40 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 57
Message-ID: <trvpl0$48dj$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me>
<20230207110711.41@kylheku.com>
Injection-Date: Wed, 8 Feb 2023 09:22:40 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="adf850dd2e53d5513311e94b23b46a24";
logging-data="139699"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19Appb54PFu2KbGQL99MNlz"
Cancel-Lock: sha1:frZZqt4qSsUgK/xhJI8XGMSkNOk=
 by: Mutt...@dastardlyhq.com - Wed, 8 Feb 2023 09:22 UTC

On Tue, 7 Feb 2023 19:33:41 -0000 (UTC)
Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>On 2023-02-07, Muttley@dastardlyhq.com <Muttley@dastardlyhq.com> wrote:
>> Its also invisible to the application program so I still don't see
>> what the difference and/or advantage of using broadcast vs signal is
>> to the application.
>
>It is completely visible to the application. Compare:
>
>"Ten threads have been woken up and are contending for the mutex in
>order the all return from their respective pthread_cond_wait calls."
>
>"One threads has been woken up and is contending for the mutex in
>order to return from pthread_cond_wait."
>
>Do you understand the api_ready example? Here it is again:
>
> bool api_ready = false;
> pthread_mutex_t api_ready_mutex = PTHREAD_MUTEX_INITIALIZER;
> pthread_cond_t api_ready_cond = PTHREAD_COND_INITIALIZER;
>
> // internal function: indicates API is ready
> static void api_becomes_ready(void)
> {
> pthread_mutex_lock(&api_mutex);
> api_ready = true;
> pthread_mutex_unlock(&api_mutex);
> pthread_cond_broadcast(&api_cond); // wake up everyone
> }
>
> void api_ready_wait(void)
> {
> pthread_mutex_lock(&api_mutex);
> while (!api_ready)
> pthread_cond_wait(&api_cond, &api_mutex);
>
> // Yes, only one thread can be here at a time
>
> pthread_mutex_unlock(&api_mutex);
>
> // Multiple threads can be returning here.
> }
>
>The api_becomes_ready function is called exactly once by the API
>itself to indicate that it is ready.
>
>Muliple threads from different subsystems may have called api_ready_wait
>in order to wait for this indication.
>
>If pthread_cond_signal is used, then quite likely, only one of those
>threads will wake up; the others will stay stuck forever.

I don't have time to write boilerplate to get this up and running but I
can't see how using broadcast instead of signal makes any difference
in how the code operates.

Re: Whats the point of pthread_cond_broadcast() ?

<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10717&group=comp.unix.programmer#10717

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 08 Feb 2023 14:56:47 +0000
Lines: 51
Message-ID: <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com>
<trvpl0$48dj$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Ec5oblok6vWL5lgcnoDFQwIWKuRacZ7zNrzBbtkRIfkrlDxGA=
Cancel-Lock: sha1:t4/FrGIa32fw6oTCBPqCHZXcO/I= sha1:VovFJ21kQbrhY1ICKr64nk5Lyh8=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Wed, 8 Feb 2023 14:56 UTC

Muttley@dastardlyhq.com writes:
> On Tue, 7 Feb 2023 19:33:41 -0000 (UTC)
> Kaz Kylheku <864-117-4973@kylheku.com> wrote:
>>On 2023-02-07, Muttley@dastardlyhq.com <Muttley@dastardlyhq.com> wrote:
>>> Its also invisible to the application program so I still don't see
>>> what the difference and/or advantage of using broadcast vs signal is
>>> to the application.
>>
>>It is completely visible to the application. Compare:
>>
>>"Ten threads have been woken up and are contending for the mutex in
>>order the all return from their respective pthread_cond_wait calls."
>>
>>"One threads has been woken up and is contending for the mutex in
>>order to return from pthread_cond_wait."
>>
>>Do you understand the api_ready example? Here it is again:
>>
>> bool api_ready = false;
>> pthread_mutex_t api_ready_mutex = PTHREAD_MUTEX_INITIALIZER;
>> pthread_cond_t api_ready_cond = PTHREAD_COND_INITIALIZER;
>>
>> // internal function: indicates API is ready
>> static void api_becomes_ready(void)
>> {
>> pthread_mutex_lock(&api_mutex);
>> api_ready = true;
>> pthread_mutex_unlock(&api_mutex);
>> pthread_cond_broadcast(&api_cond); // wake up everyone
>> }

[...]

>>The api_becomes_ready function is called exactly once by the API
>>itself to indicate that it is ready.
>>
>>Muliple threads from different subsystems may have called api_ready_wait
>>in order to wait for this indication.
>>
>>If pthread_cond_signal is used, then quite likely, only one of those
>>threads will wake up; the others will stay stuck forever.
>
> I don't have time to write boilerplate to get this up and running but I
> can't see how using broadcast instead of signal makes any difference
> in how the code operates.

As written, the code is correct with _broadcast and wouldn't be with
signal. Any number of threads can be waiting for the api to become
ready. Hence, whatever threads are actually waiting by that time must be
woken up as they'll otherwise sleep forever.

Re: Whats the point of pthread_cond_broadcast() ?

<ts0gdd$8207$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10718&group=comp.unix.programmer#10718

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 8 Feb 2023 15:51:09 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <ts0gdd$8207$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com>
<trvpl0$48dj$1@dont-email.me>
<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
Injection-Date: Wed, 8 Feb 2023 15:51:09 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="adf850dd2e53d5513311e94b23b46a24";
logging-data="264199"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX192jjCrHMU+t2mKwk3Gw0Ii"
Cancel-Lock: sha1:SDCLlzX3Y28Cnnpn4VwyX0m/9lQ=
 by: Mutt...@dastardlyhq.com - Wed, 8 Feb 2023 15:51 UTC

On Wed, 08 Feb 2023 14:56:47 +0000
Rainer Weikusat <rweikusat@talktalk.net> wrote:
>Muttley@dastardlyhq.com writes:
>> I don't have time to write boilerplate to get this up and running but I
>> can't see how using broadcast instead of signal makes any difference
>> in how the code operates.
>
>As written, the code is correct with _broadcast and wouldn't be with
>signal. Any number of threads can be waiting for the api to become
>ready. Hence, whatever threads are actually waiting by that time must be
>woken up as they'll otherwise sleep forever.

Yes, they all get woken up then they all go back to sleep again except 1
without doing anything. Sorry, still not seeing it.

Re: Whats the point of pthread_cond_broadcast() ?

<_HPEL.638934$iU59.175216@fx14.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10719&group=comp.unix.programmer#10719

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.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: Whats the point of pthread_cond_broadcast() ?
Newsgroups: comp.unix.programmer
References: <trqgmc$312l3$1@dont-email.me> <5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au> <trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me>
Lines: 19
Message-ID: <_HPEL.638934$iU59.175216@fx14.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 08 Feb 2023 16:02:02 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 08 Feb 2023 16:02:02 GMT
X-Received-Bytes: 1738
 by: Scott Lurndal - Wed, 8 Feb 2023 16:02 UTC

Muttley@dastardlyhq.com writes:
>On Wed, 08 Feb 2023 14:56:47 +0000
>Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>Muttley@dastardlyhq.com writes:
>>> I don't have time to write boilerplate to get this up and running but I
>>> can't see how using broadcast instead of signal makes any difference
>>> in how the code operates.
>>
>>As written, the code is correct with _broadcast and wouldn't be with
>>signal. Any number of threads can be waiting for the api to become
>>ready. Hence, whatever threads are actually waiting by that time must be
>>woken up as they'll otherwise sleep forever.
>
>Yes, they all get woken up then they all go back to sleep again except 1
>without doing anything. Sorry, still not seeing it.

But the will be sleeping on the mutex, not the condition variable
at that point. A far different sleep entirely.

Re: Whats the point of pthread_cond_broadcast() ?

<ts0h68$869b$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10720&group=comp.unix.programmer#10720

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 8 Feb 2023 16:04:24 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <ts0h68$869b$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me> <5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au> <trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad>
Injection-Date: Wed, 8 Feb 2023 16:04:24 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="adf850dd2e53d5513311e94b23b46a24";
logging-data="268587"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/nbLN2djXOHzsXSh2gM1tW"
Cancel-Lock: sha1:8gLbOFGNfCqbMJ2HeOlouKUtK4c=
 by: Mutt...@dastardlyhq.com - Wed, 8 Feb 2023 16:04 UTC

On Wed, 08 Feb 2023 16:02:02 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
>Muttley@dastardlyhq.com writes:
>>On Wed, 08 Feb 2023 14:56:47 +0000
>>Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>>Muttley@dastardlyhq.com writes:
>>>> I don't have time to write boilerplate to get this up and running but I
>>>> can't see how using broadcast instead of signal makes any difference
>>>> in how the code operates.
>>>
>>>As written, the code is correct with _broadcast and wouldn't be with
>>>signal. Any number of threads can be waiting for the api to become
>>>ready. Hence, whatever threads are actually waiting by that time must be
>>>woken up as they'll otherwise sleep forever.
>>
>>Yes, they all get woken up then they all go back to sleep again except 1
>>without doing anything. Sorry, still not seeing it.
>
>But the will be sleeping on the mutex, not the condition variable
>at that point. A far different sleep entirely.

If they're all sleeping on a mutex you don't need condition variables to
start with. Whether you use signal or broadcast ONLY ONE thread exits the
wait. The behaviour from an application program POV is identical.

Re: Whats the point of pthread_cond_broadcast() ?

<IcQEL.127182$Ldj8.119120@fx47.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10721&group=comp.unix.programmer#10721

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx47.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: Whats the point of pthread_cond_broadcast() ?
Newsgroups: comp.unix.programmer
References: <trqgmc$312l3$1@dont-email.me> <5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au> <trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me>
Lines: 39
Message-ID: <IcQEL.127182$Ldj8.119120@fx47.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 08 Feb 2023 16:36:56 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 08 Feb 2023 16:36:56 GMT
X-Received-Bytes: 2884
 by: Scott Lurndal - Wed, 8 Feb 2023 16:36 UTC

Muttley@dastardlyhq.com writes:
>On Wed, 08 Feb 2023 16:02:02 GMT
>scott@slp53.sl.home (Scott Lurndal) wrote:
>>Muttley@dastardlyhq.com writes:
>>>On Wed, 08 Feb 2023 14:56:47 +0000
>>>Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>>>Muttley@dastardlyhq.com writes:
>>>>> I don't have time to write boilerplate to get this up and running but I
>>>>> can't see how using broadcast instead of signal makes any difference
>>>>> in how the code operates.
>>>>
>>>>As written, the code is correct with _broadcast and wouldn't be with
>>>>signal. Any number of threads can be waiting for the api to become
>>>>ready. Hence, whatever threads are actually waiting by that time must be
>>>>woken up as they'll otherwise sleep forever.
>>>
>>>Yes, they all get woken up then they all go back to sleep again except 1
>>>without doing anything. Sorry, still not seeing it.
>>
>>But the will be sleeping on the mutex, not the condition variable
>>at that point. A far different sleep entirely.
>
>If they're all sleeping on a mutex you don't need condition variables to
>start with. Whether you use signal or broadcast ONLY ONE thread exits the
>wait. The behaviour from an application program POV is identical.
>

No, when you use broadcast, _all_ threads exit the wait for the event
and start waiting for the mutex. Subsequently, as each thread gets
the mutex, does something in the critical region, then releases
the mutex, the remaining threads will contend for mutex, perform
the critical region and release the mutex. They won't be still waiting
on the condition variable until each thread calls pthread_cond_wait* again.

The difference between signal and broadcast is _what_ the remaining
threads end up waiting for. In the former, the remaining threads
continue to wait on the condition variable; in the latter the
remaining threads contend for the mutex protecting the resource/critical
section.

Re: Whats the point of pthread_cond_broadcast() ?

<87fsbg6rag.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10722&group=comp.unix.programmer#10722

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 08 Feb 2023 16:44:07 +0000
Lines: 20
Message-ID: <87fsbg6rag.fsf@doppelsaurus.mobileactivedefense.com>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com>
<trvpl0$48dj$1@dont-email.me>
<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
<ts0gdd$8207$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Di4a7cVp30Q8pl2xfHn+Mgw3nXEezwEdVbhn0LBQTsRGw/zuY=
Cancel-Lock: sha1:6EmU5AoiceMwS/f/DzQ+Socen9w= sha1:Ax1YWaRNcFnMUb4uqiO+xNCaxg0=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Wed, 8 Feb 2023 16:44 UTC

Muttley@dastardlyhq.com writes:
> Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>Muttley@dastardlyhq.com writes:
>>> I don't have time to write boilerplate to get this up and running but I
>>> can't see how using broadcast instead of signal makes any difference
>>> in how the code operates.
>>
>>As written, the code is correct with _broadcast and wouldn't be with
>>signal. Any number of threads can be waiting for the api to become
>>ready. Hence, whatever threads are actually waiting by that time must be
>>woken up as they'll otherwise sleep forever.
>
> Yes, they all get woken up then they all go back to sleep again except 1
> without doing anything. Sorry, still not seeing it.

Without broadcast, only one thread sleeping on the queue of the
condition variable would ever be woken up. All others would remain
sleeping there forever. If they're instead sleeping the queue of the
mutex, they'd eventually all be woken up due to mutex unlock operations.

Re: Whats the point of pthread_cond_broadcast() ?

<ts0jo2$8k6d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10723&group=comp.unix.programmer#10723

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 8 Feb 2023 16:48:02 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 26
Message-ID: <ts0jo2$8k6d$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me> <5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au> <trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad>
Injection-Date: Wed, 8 Feb 2023 16:48:02 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="adf850dd2e53d5513311e94b23b46a24";
logging-data="282829"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+nzFGJeRt3gWT29CBQTiBp"
Cancel-Lock: sha1:P09l6K6MhgxnqsK1HQ5WJaEzqn8=
 by: Mutt...@dastardlyhq.com - Wed, 8 Feb 2023 16:48 UTC

On Wed, 08 Feb 2023 16:36:56 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
>Muttley@dastardlyhq.com writes:
>>If they're all sleeping on a mutex you don't need condition variables to
>>start with. Whether you use signal or broadcast ONLY ONE thread exits the
>>wait. The behaviour from an application program POV is identical.
>>
>
>No, when you use broadcast, _all_ threads exit the wait for the event
>and start waiting for the mutex. Subsequently, as each thread gets
>the mutex, does something in the critical region, then releases
>the mutex, the remaining threads will contend for mutex, perform
>the critical region and release the mutex. They won't be still waiting
>on the condition variable until each thread calls pthread_cond_wait* again.
>
>The difference between signal and broadcast is _what_ the remaining
>threads end up waiting for. In the former, the remaining threads
>continue to wait on the condition variable; in the latter the
>remaining threads contend for the mutex protecting the resource/critical
>section.

Ok, someone finally explained it in a comprehensible way. Thanks.

Nowhere have I read that inside pthread_cond_wait() there are 2 possible thread
states which you have to be aware of. What a bloody awful API design.

Re: Whats the point of pthread_cond_broadcast() ?

<87bkm46qqg.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10724&group=comp.unix.programmer#10724

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 08 Feb 2023 16:56:07 +0000
Lines: 36
Message-ID: <87bkm46qqg.fsf@doppelsaurus.mobileactivedefense.com>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com>
<trvpl0$48dj$1@dont-email.me>
<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
<ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad>
<ts0h68$869b$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net qwd8AHxCKTCU2Z2tzoV5ogl7+RuRxhrUN8iZAxwD8GMMUW4BA=
Cancel-Lock: sha1:MqWfPT94H3OoM4OHroQFHcgvLfM= sha1:+iBX+LKj8O/lE1AcEnSZHoO6Hc0=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Wed, 8 Feb 2023 16:56 UTC

Muttley@dastardlyhq.com writes:
> On Wed, 08 Feb 2023 16:02:02 GMT
> scott@slp53.sl.home (Scott Lurndal) wrote:
>>Muttley@dastardlyhq.com writes:
>>>On Wed, 08 Feb 2023 14:56:47 +0000
>>>Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>>>Muttley@dastardlyhq.com writes:
>>>>> I don't have time to write boilerplate to get this up and running but I
>>>>> can't see how using broadcast instead of signal makes any difference
>>>>> in how the code operates.
>>>>
>>>>As written, the code is correct with _broadcast and wouldn't be with
>>>>signal. Any number of threads can be waiting for the api to become
>>>>ready. Hence, whatever threads are actually waiting by that time must be
>>>>woken up as they'll otherwise sleep forever.
>>>
>>>Yes, they all get woken up then they all go back to sleep again except 1
>>>without doing anything. Sorry, still not seeing it.
>>
>>But the will be sleeping on the mutex, not the condition variable
>>at that point. A far different sleep entirely.
>
> If they're all sleeping on a mutex you don't need condition variables to
> start with.

A locked mutex has an owner and implementations may throw an error if a
thread other than the one which owns the mutex tries to unlock it (NPTL
does). Condition variables can be signalled by any thread.

> Whether you use signal or broadcast ONLY ONE thread exits the
> wait. The behaviour from an application program POV is identical.

.... until this one thread unlocks the mutex. If broadcast had been used
on the condition variable, another thread originally sleeping on that
will now start to run. Otherwise, the outcome is an unlocked mutex and a set
of threads still sleeping on something else.

Re: Whats the point of pthread_cond_broadcast() ?

<aHQEL.430433$gGD7.95617@fx11.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10725&group=comp.unix.programmer#10725

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx11.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: Whats the point of pthread_cond_broadcast() ?
Newsgroups: comp.unix.programmer
References: <trqgmc$312l3$1@dont-email.me> <5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au> <trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me>
Lines: 31
Message-ID: <aHQEL.430433$gGD7.95617@fx11.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 08 Feb 2023 17:09:26 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 08 Feb 2023 17:09:26 GMT
X-Received-Bytes: 2472
 by: Scott Lurndal - Wed, 8 Feb 2023 17:09 UTC

Muttley@dastardlyhq.com writes:
>On Wed, 08 Feb 2023 16:36:56 GMT
>scott@slp53.sl.home (Scott Lurndal) wrote:
>>Muttley@dastardlyhq.com writes:
>>>If they're all sleeping on a mutex you don't need condition variables to
>>>start with. Whether you use signal or broadcast ONLY ONE thread exits the
>>>wait. The behaviour from an application program POV is identical.
>>>
>>
>>No, when you use broadcast, _all_ threads exit the wait for the event
>>and start waiting for the mutex. Subsequently, as each thread gets
>>the mutex, does something in the critical region, then releases
>>the mutex, the remaining threads will contend for mutex, perform
>>the critical region and release the mutex. They won't be still waiting
>>on the condition variable until each thread calls pthread_cond_wait* again.
>>
>>The difference between signal and broadcast is _what_ the remaining
>>threads end up waiting for. In the former, the remaining threads
>>continue to wait on the condition variable; in the latter the
>>remaining threads contend for the mutex protecting the resource/critical
>>section.
>
>Ok, someone finally explained it in a comprehensible way. Thanks.
>
>Nowhere have I read that inside pthread_cond_wait() there are 2 possible thread
>states which you have to be aware of. What a bloody awful API design.
>

This seems pretty clear to me:

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

Re: Whats the point of pthread_cond_broadcast() ?

<ts0l5t$8s8d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10726&group=comp.unix.programmer#10726

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 8 Feb 2023 17:12:29 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <ts0l5t$8s8d$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me> <5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au> <trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad>
Injection-Date: Wed, 8 Feb 2023 17:12:29 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="adf850dd2e53d5513311e94b23b46a24";
logging-data="291085"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19wf9hhIBBvlx2MYAuMl6V1"
Cancel-Lock: sha1:eVpZwxJkXwugU/INqrRnLoWtgz4=
 by: Mutt...@dastardlyhq.com - Wed, 8 Feb 2023 17:12 UTC

On Wed, 08 Feb 2023 17:09:26 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
>Muttley@dastardlyhq.com writes:
>>On Wed, 08 Feb 2023 16:36:56 GMT
>>scott@slp53.sl.home (Scott Lurndal) wrote:
>>>Muttley@dastardlyhq.com writes:
>>>>If they're all sleeping on a mutex you don't need condition variables to
>>>>start with. Whether you use signal or broadcast ONLY ONE thread exits the
>>>>wait. The behaviour from an application program POV is identical.
>>>>
>>>
>>>No, when you use broadcast, _all_ threads exit the wait for the event
>>>and start waiting for the mutex. Subsequently, as each thread gets
>>>the mutex, does something in the critical region, then releases
>>>the mutex, the remaining threads will contend for mutex, perform
>>>the critical region and release the mutex. They won't be still waiting
>>>on the condition variable until each thread calls pthread_cond_wait* again.
>>>
>>>The difference between signal and broadcast is _what_ the remaining
>>>threads end up waiting for. In the former, the remaining threads
>>>continue to wait on the condition variable; in the latter the
>>>remaining threads contend for the mutex protecting the resource/critical
>>>section.
>>
>>Ok, someone finally explained it in a comprehensible way. Thanks.
>>
>>Nowhere have I read that inside pthread_cond_wait() there are 2 possible
>thread
>>states which you have to be aware of. What a bloody awful API design.
>>
>
>This seems pretty clear to me:
>
>https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cond_wait.ht
>ml

"Once all waiting threads have been unblocked (as by the
pthread_cond_broadcast() operation), the next wait operation on that condition
variable shall form a new dynamic binding with the mutex specified by that wait
operation. Even though the dynamic binding between condition variable and mutex
may be removed or replaced between the time a thread is unblocked from a wait on
the condition variable blah blah blah ....."

I'm not sure what your definition of "clear" is but its obviously very different
to mine.

Re: Whats the point of pthread_cond_broadcast() ?

<877cws6p2m.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10727&group=comp.unix.programmer#10727

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.samoylyk.net!news.szaf.org!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Wed, 08 Feb 2023 17:32:01 +0000
Lines: 21
Message-ID: <877cws6p2m.fsf@doppelsaurus.mobileactivedefense.com>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com>
<trvpl0$48dj$1@dont-email.me>
<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
<ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad>
<ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad>
<ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad>
<ts0l5t$8s8d$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net faxk/nRe0kiU0u0jSTjxBwyZfbNohpMb+8oCFfqWAphpQ7Yyw=
Cancel-Lock: sha1:XeXdaFRrMdcjj/ZxSmfoaQWCy+4= sha1:hWNF1uFbMNsrnxhs/9tvVSueLg4=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Wed, 8 Feb 2023 17:32 UTC

Muttley@dastardlyhq.com writes:

[...]

> "Once all waiting threads have been unblocked (as by the
> pthread_cond_broadcast() operation), the next wait operation on that condition
> variable shall form a new dynamic binding with the mutex specified by that wait
> operation. Even though the dynamic binding between condition variable and mutex
> may be removed or replaced between the time a thread is unblocked from a wait on
> the condition variable blah blah blah ....."
>
> I'm not sure what your definition of "clear" is but its obviously very different
> to mine.

This seems clear to me: Assuming a condition variable c is initially
idle, ie, there are not threads waiting on in, the mutex m used in the
first call to pthread_cond_wait on c must be recorded somewhere to
enable woken-up threads to acquire the correct mutex. A new mutex mm can be
associated with c once all threads sleeping on c+m have been woken up. But
this shall not affect threads which haven't yet returned to the caller
which slept on c while it was still associated with m.

Re: Whats the point of pthread_cond_broadcast() ?

<63e40be0$0$2999$426a74cc@news.free.fr>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10728&group=comp.unix.programmer#10728

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.nntp4.net!news.gegeweb.eu!gegeweb.org!usenet-fr.net!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!cleanfeed1-a.proxad.net!nnrp1-2.free.fr!not-for-mail
Newsgroups: comp.unix.programmer
From: nicolas$...@salle-s.org (Nicolas George)
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Sender: george@phare.invalid (Nicolas George)
X-Newsreader: Flrn (0.9.20070704)
References: <trqgmc$312l3$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad>
MIME-Version: 1.0
Content-Transfer-Encoding: 8bit
Content-Type: text/plain; charset=iso-8859-1
Date: 08 Feb 2023 20:53:53 GMT
Lines: 9
Message-ID: <63e40be0$0$2999$426a74cc@news.free.fr>
Organization: Guest of ProXad - France
NNTP-Posting-Date: 08 Feb 2023 21:53:53 CET
NNTP-Posting-Host: 129.199.129.80
X-Trace: 1675889633 news-3.free.fr 2999 129.199.129.80:47532
X-Complaints-To: abuse@proxad.net
 by: Nicolas George - Wed, 8 Feb 2023 20:53 UTC

Scott Lurndal, dans le message <aHQEL.430433$gGD7.95617@fx11.iad>, a
écrit :
> This seems pretty clear to me:

Not only is it clear, but it is also entirely natural. Once you have threads
of the kind of POSIX threads and mutexes, if you think what API you need to
implement the kind of things conditions are for, and then you compare with
what conditions actually do, your solution is usually more or less the same,
but the condition API is sleeker.

Re: Whats the point of pthread_cond_broadcast() ?

<WdUEL.364534$t5W7.59485@fx13.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10729&group=comp.unix.programmer#10729

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx13.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: Whats the point of pthread_cond_broadcast() ?
Newsgroups: comp.unix.programmer
References: <trqgmc$312l3$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad> <63e40be0$0$2999$426a74cc@news.free.fr>
Lines: 405
Message-ID: <WdUEL.364534$t5W7.59485@fx13.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 08 Feb 2023 21:11:18 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 08 Feb 2023 21:11:18 GMT
X-Received-Bytes: 24177
 by: Scott Lurndal - Wed, 8 Feb 2023 21:11 UTC

Nicolas George <nicolas$george@salle-s.org> writes:
>Scott Lurndal, dans le message <aHQEL.430433$gGD7.95617@fx11.iad>, a
> �crit�:
>> This seems pretty clear to me:
>
>Not only is it clear, but it is also entirely natural. Once you have threads
>of the kind of POSIX threads and mutexes, if you think what API you need to
>implement the kind of things conditions are for, and then you compare with
>what conditions actually do, your solution is usually more or less the same,
>but the condition API is sleeker.

Indeed. It is rather similar to the hardware-based mutual exclusion
and event (condition) mechanism we invented for a Burroughs mainframe
around 1982. The LOK instruction was implemented in hardware, OS (MCP)
scheduling was performed in a microkernel that handled all interrupts
and scheduled the highest priority ready task (and very little else other
than timers). The MCP ran at a slightly less privileged level when
processing "system calls" on behalf of a user task (known as Branch Communicate,
i.e. the BCT instruction). The main difference with POSIX is the atomic
releasing of the mutex during the condition wait function.

===== Lock/Unlock (LOK)/OP=60 =====

==== Format ====

^ OP ^ AF ^ BF ^ A Syllable ^

''OP = 60''

**AF** Unused and reserved; can be specified as an indirect field length. A literal flag causes an invalid instruction fault (IEX = 21).\\
**BF** Instruction variant; can be indirect.

^ Variant ^ Function ^
| 10 | Event cause no interrupt |
| 09 | Event cause and reset |
| 08 | Event reset and wait |
| 07 | Test happened status |
| 06 | Event reset |
| 05 | Event wait |
| 04 | Event cause |
| 02 | Conditional lock |
| 01 | Unconditional lock |
| 00 | Unlock |

All other BF values cause an invalid instruction fault (IEX = 26).

**A** is the address of the lock/event structure. Address can be indexed, indirect, or extended. The final address controller must be UN, or an invalid instruction fault (IEX = 03) occurs. The final address must be Mod-2, but the hardware does not check it.\\
If BF has a value of 00-02, A represents a lock structure.\\
If BF has a value of 04-10, A represents an event structure.

The lock structure format is as follows:

^ Information ^ Digits ^
| Lock status field | 00-01 |
| Lock owner field | 02-05 |
| Lock waiter link field | 06-09 |
| Lock number field | 10-13 |
| Lock number link field | 14-17 |
| Reserved | 18-19 |

^ Note: The lowest memory address is 00.^

The event structure format is as follows:

^ Information ^ Digits ^
| Event status field | 00-01 |
| Event owner field | 02-05 |
| Event waiter link field | 06-09 |
| Event designator field | 10-13 |
| Event count | 14-19 |

^ Note: The lowest memory address is 00. ^

If any of the lock/event structure values contain undigits, an invalid
instruction (IEX=07) occurs.

^ Note: This instruction only executes with the privileged enable set otherwise an invalid instruction fault (IEX=02) is reported. ^

==== Function ====

LOK examines the lock/event structure (A) and, depending on its value
and the instruction variant (BF), modifies the lock/event structure
(A) and associated lock fields in the [[processor_state:reinstate_list|reinstate list]] entry for the
current task, and other tasks owning or contending for the lock or
event.

The lock waiter link field and the event waiter link field provide the
MCP kernel with the task number, which execution is linked to, for a
specific change of the current lock or event structure.

The lock number field and the lock number link field implement a
canonical lock algorithm to prevent deadlock situations. All locks are
assigned a level number; a task that owns a lock at level
n can only get a lock at level n+1 or greater. A
lock at a level lower than n can be acquired only by a task that
has released all locks at or above that level in reverse order from which
it had acquired them.

The processor must determine if a lock is owned or available. If the
owner field of the lock structure is zero, the lock is available. If the
owner field is not zero, the lock is owned.

The processor must determine if an event has happened. If the event owner
field is zero, the event has happened. If the event state field is not
equal to zero, the event has not happened.

The event designator field ensures that the current structure is an event
structure. A nonzero value in this field causes a fault.

^ Note: The equivalent field in a lock structure (lock number) is always a nonzero value. ^

The event count field identifies a particular occurrence of a particular
event since the same structure can be used for multiple purposes over a
period of time.

The machine-dependent lock status field of the lock/even structure (A)
can also represent the status of the structure, with one value
representing owned, and another representing available. The lock status
field of the lock structure is not used to determine if the lock is
available.

==== Variants ====

The variants are described as follows:

=== BF=00 Unlock ===

This variant releases a Lock and, if any task is waiting for this lock, causes
an interrupt to the MCP kernel.

Obtain exclusive rights to the lock structure specified by the A address.

The value of the lock owner field must equal the current task
number; otherwise, relinquish exclusive access rights
to the lock structure, cause an invalid instruction fault (IEX=06)
and terminate the instruction with no futher action.

Compare the lock number field of the lock structure (A)
with the MCP canonical lock number field located in the
[[processor_state:reinstate_list|reinstate list entry]] for the current task. If they are not
equal, relinquish exclusive access rights to the lock
structure; cause an invalid instruction fault (IEX=06) and
terminate the instruction with no further action.

Otherwise, store zeros into the lock owner field of the
lock structure (A) to indicate that this lock is available.
It also stores the contents of the lock number link field of
the lock structure (A) into the MCP canonical lock number
field that is located in the reinstate list entry for the
current task.

Examine the lock waiter link field of the lock structure. If it is equal to
zero, set the [[processor_state:comparison_flags|Comparison flags]] to **EQUAL**, relinquish exclusive access rights to
the lock structure and terminate the instruction with no further action.

If the lock waiter link field is not equal to zero, perform the following
operations:
- Set the comparison flags to HIGH.
- Assemble and save, within the processor, the released contended lock value for future update of the instruction interrupt cause descriptor in the [[processor_state:kernel_data_area|kernel data area]].
- Assemble and save, within the processor, the pointer to the reinstate list entry of the task specified by the task number in the lock waiter link field of the lock structure (A). The pointer is to be used for update to the instruction interrupt cause extension descriptor (C7AAAAAA).
- Assemble and save, within the processor, the next instruction address. The next instruction address will be used to update the interrupt frame in the reinstate list entry for the current task.
- Relinquish exclusive access rights to the lock structure.
- Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the [[processor_state:kernel_data_area|kernel data area]].

=== BF=01 Unconditional Lock ===

This variant competes for the lock specified by the Lock Structure (A) and, if
the lock is owned, causes an interrupt to the MCP kernel.

Obtain exclusive rights to the lock structure specified by the A address.

Compare the lock number field of the lock structure (A) with the MCP canonical lock number field located in the reinstate list entry for the current task. If the lock number field is less than or equal to the MCP canonical lock number field, relinquish exclusive access rights to the lock structure, raise an invalid instruction fault (IEX=06) and terminate the instruction.

If the lock is available, perform the following operations:
- Store the active task number in the lock owner field.
- Copy the contents of the MCP canonical lock number field, that is located in the active reinstate list entry, into the lock number link field of the lock structure.
- Copy the contents of the lock number field of the lock structure into the MCP canonical lock number field that is located in the active reinstate list entry.
- Set the comparison flags to **EQUAL**.
- Relinquish exclusive access rights to the lock structure and terminate the instruction.

If the lock is owned, perfrom the following operations:
- Copy the lock owner field of the lock structure (A) into the task number owning field located in the reinstate list entry for the current task.
- Copy the lock waiter link field of the lock structure (A) to the next task in list field located in the reinstate list entry for the current task.
- Store the current task number into the lock waiter link field of the lock structure (A).
- Store the waiting lock value into the state indicator field located in the reinstate list entry for the current task.
- Set the comparison flags to LOW.
- Assemble and save, within the processor, the failed lock value for update of the instruction interrupt cause descriptor in the kernel data area.
- Assemble and save, within the processor the pointer to the reinstate list entry of the task specified by the task number in the lock owner field of the lock structure (A). The pointer is to be used for update to the instruction interrupt cause extension descriptor (C7AAAAAA).
- Assemble and save, within the processor, the next instruction address to point to the instruction following the current instruction for future update of the interrupt frame in the reinstate list entry for the current task.
- Relinquish exclusive access rights to the lock structure.
- Perform an interrupt procedure that reports an instruction interrupt in the interrupt descriptor in the kernel data area.


Click here to read the complete article
Re: Whats the point of pthread_cond_broadcast() ?

<ts2ea5$kr94$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10730&group=comp.unix.programmer#10730

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Thu, 9 Feb 2023 09:27:33 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 38
Message-ID: <ts2ea5$kr94$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com>
<trvpl0$48dj$1@dont-email.me>
<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
<ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad>
<ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad>
<ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad>
<ts0l5t$8s8d$1@dont-email.me>
<877cws6p2m.fsf@doppelsaurus.mobileactivedefense.com>
Injection-Date: Thu, 9 Feb 2023 09:27:33 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="fc415c9f3810cd1fe9102ee1c41638bf";
logging-data="683300"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19L2wr9+nixQFbFx10A+EkM"
Cancel-Lock: sha1:rKeKmEJO8CI1mNMcjG+tz4m6iYk=
 by: Mutt...@dastardlyhq.com - Thu, 9 Feb 2023 09:27 UTC

On Wed, 08 Feb 2023 17:32:01 +0000
Rainer Weikusat <rweikusat@talktalk.net> wrote:
>Muttley@dastardlyhq.com writes:
>
>[...]
>
>> "Once all waiting threads have been unblocked (as by the
>> pthread_cond_broadcast() operation), the next wait operation on that
>condition
>> variable shall form a new dynamic binding with the mutex specified by that
>wait
>> operation. Even though the dynamic binding between condition variable and
>mutex
>> may be removed or replaced between the time a thread is unblocked from a
>wait on
>> the condition variable blah blah blah ....."
>>
>> I'm not sure what your definition of "clear" is but its obviously very
>different
>> to mine.
>
>This seems clear to me: Assuming a condition variable c is initially
>idle, ie, there are not threads waiting on in, the mutex m used in the
>first call to pthread_cond_wait on c must be recorded somewhere to
>enable woken-up threads to acquire the correct mutex. A new mutex mm can be
>associated with c once all threads sleeping on c+m have been woken up. But
>this shall not affect threads which haven't yet returned to the caller
>which slept on c while it was still associated with m.

No.

Clear would be:

"Once the thread is woken up on the condition variable it then waits on
the mutex AND DOES NOT EXIT pthread_cond_wait() until it aquires it."

That is clarity, not the technogibberish above.

Re: Whats the point of pthread_cond_broadcast() ?

<ts2edf$krh3$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10731&group=comp.unix.programmer#10731

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Thu, 9 Feb 2023 09:29:19 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <ts2edf$krh3$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad> <63e40be0$0$2999$426a74cc@news.free.fr> <WdUEL.364534$t5W7.59485@fx13.iad>
Injection-Date: Thu, 9 Feb 2023 09:29:19 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="fc415c9f3810cd1fe9102ee1c41638bf";
logging-data="683555"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19yLktdojsIMrRdtVU/yNgu"
Cancel-Lock: sha1:IRkKnRDRr2wWOv1oV5JHZkxqy2Q=
 by: Mutt...@dastardlyhq.com - Thu, 9 Feb 2023 09:29 UTC

On Wed, 08 Feb 2023 21:11:18 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
>Nicolas George <nicolas$george@salle-s.org> writes:
>>Scott Lurndal, dans le message <aHQEL.430433$gGD7.95617@fx11.iad>, a
>> �crit�:
>>> This seems pretty clear to me:
>>
>>Not only is it clear, but it is also entirely natural. Once you have threads
>>of the kind of POSIX threads and mutexes, if you think what API you need to
>>implement the kind of things conditions are for, and then you compare with
>>what conditions actually do, your solution is usually more or less the same,
>>but the condition API is sleeker.
>
>Indeed. It is rather similar to the hardware-based mutual exclusion
>and event (condition) mechanism we invented for a Burroughs mainframe
>around 1982. The LOK instruction was implemented in hardware, OS (MCP)

Did the Tron scriptwriters nick the MCP acronym from you or you from them? :)

Re: Whats the point of pthread_cond_broadcast() ?

<vH7FL.176892$PXw7.109888@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10732&group=comp.unix.programmer#10732

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.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: Whats the point of pthread_cond_broadcast() ?
Newsgroups: comp.unix.programmer
References: <trqgmc$312l3$1@dont-email.me> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad> <ts0l5t$8s8d$1@dont-email.me> <877cws6p2m.fsf@doppelsaurus.mobileactivedefense.com> <ts2ea5$kr94$1@dont-email.me>
Lines: 58
Message-ID: <vH7FL.176892$PXw7.109888@fx45.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 09 Feb 2023 14:46:51 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 09 Feb 2023 14:46:51 GMT
X-Received-Bytes: 3254
 by: Scott Lurndal - Thu, 9 Feb 2023 14:46 UTC

Muttley@dastardlyhq.com writes:
>On Wed, 08 Feb 2023 17:32:01 +0000
>Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>Muttley@dastardlyhq.com writes:
>>
>>[...]
>>
>>> "Once all waiting threads have been unblocked (as by the
>>> pthread_cond_broadcast() operation), the next wait operation on that
>>condition
>>> variable shall form a new dynamic binding with the mutex specified by that
>>wait
>>> operation. Even though the dynamic binding between condition variable and
>>mutex
>>> may be removed or replaced between the time a thread is unblocked from a
>>wait on
>>> the condition variable blah blah blah ....."
>>>
>>> I'm not sure what your definition of "clear" is but its obviously very
>>different
>>> to mine.
>>
>>This seems clear to me: Assuming a condition variable c is initially
>>idle, ie, there are not threads waiting on in, the mutex m used in the
>>first call to pthread_cond_wait on c must be recorded somewhere to
>>enable woken-up threads to acquire the correct mutex. A new mutex mm can be
>>associated with c once all threads sleeping on c+m have been woken up. But
>>this shall not affect threads which haven't yet returned to the caller
>>which slept on c while it was still associated with m.
>
>No.
>
>Clear would be:
>
>"Once the thread is woken up on the condition variable it then waits on
>the mutex AND DOES NOT EXIT pthread_cond_wait() until it aquires it."
>
>That is clarity, not the technogibberish above.

The paragraph you call technogibberish has nothing to do with
what happens with the mutex, it's more of an internal implementation
detail and a warning to the implementer and the user of the effects of using a single
condition variable with different mutexes.

This paragraph:

Upon successful return, the mutex shall have been locked and
shall be owned by the calling thread.

Is clear and states exactly what you said "clear would be" above.

Perhaps

... the mutex shall have been acquired as if by
pthread_mutex_lock and shall be owned...

would be slightly more clear, but the current statement is clear to
those skilled in the art, which is generally the point of a standard.

Re: Whats the point of pthread_cond_broadcast() ?

<qK7FL.176893$PXw7.63369@fx45.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10733&group=comp.unix.programmer#10733

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx45.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: Whats the point of pthread_cond_broadcast() ?
Newsgroups: comp.unix.programmer
References: <trqgmc$312l3$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad> <63e40be0$0$2999$426a74cc@news.free.fr> <WdUEL.364534$t5W7.59485@fx13.iad> <ts2edf$krh3$1@dont-email.me>
Lines: 27
Message-ID: <qK7FL.176893$PXw7.63369@fx45.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 09 Feb 2023 14:49:58 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 09 Feb 2023 14:49:58 GMT
X-Received-Bytes: 2178
 by: Scott Lurndal - Thu, 9 Feb 2023 14:49 UTC

Muttley@dastardlyhq.com writes:
>On Wed, 08 Feb 2023 21:11:18 GMT
>scott@slp53.sl.home (Scott Lurndal) wrote:
>>Nicolas George <nicolas$george@salle-s.org> writes:
>>>Scott Lurndal, dans le message <aHQEL.430433$gGD7.95617@fx11.iad>, a
>>> �crit�:
>>>> This seems pretty clear to me:
>>>
>>>Not only is it clear, but it is also entirely natural. Once you have threads
>>>of the kind of POSIX threads and mutexes, if you think what API you need to
>>>implement the kind of things conditions are for, and then you compare with
>>>what conditions actually do, your solution is usually more or less the same,
>>>but the condition API is sleeker.
>>
>>Indeed. It is rather similar to the hardware-based mutual exclusion
>>and event (condition) mechanism we invented for a Burroughs mainframe
>>around 1982. The LOK instruction was implemented in hardware, OS (MCP)
>
>Did the Tron scriptwriters nick the MCP acronym from you or you from them? :)

We were using MCP long before the movie. We (the MCP department) took
a morning off to go to see Tron at a nearby (walking distance) theater
when it came out (the theater was also rented for periodic all-hands
meetings). This was in Pasadena California.

I doubt the scriptwriters had even heard of Burroughs MCP; likely
a parallel development.

Re: Whats the point of pthread_cond_broadcast() ?

<ts3677$ng29$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10734&group=comp.unix.programmer#10734

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: Mutt...@dastardlyhq.com
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Thu, 9 Feb 2023 16:15:35 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <ts3677$ng29$1@dont-email.me>
References: <trqgmc$312l3$1@dont-email.me> <trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me> <87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com> <ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad> <ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad> <ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad> <ts0l5t$8s8d$1@dont-email.me> <877cws6p2m.fsf@doppelsaurus.mobileactivedefense.com> <ts2ea5$kr94$1@dont-email.me>
<vH7FL.176892$PXw7.109888@fx45.iad>
Injection-Date: Thu, 9 Feb 2023 16:15:35 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="fc415c9f3810cd1fe9102ee1c41638bf";
logging-data="770121"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+PkjwPsVJ7vd9+5/MANPnx"
Cancel-Lock: sha1:vPctBiuPwD6GvjqUvdIbee5p4jM=
 by: Mutt...@dastardlyhq.com - Thu, 9 Feb 2023 16:15 UTC

On Thu, 09 Feb 2023 14:46:51 GMT
scott@slp53.sl.home (Scott Lurndal) wrote:
>Muttley@dastardlyhq.com writes:
>>On Wed, 08 Feb 2023 17:32:01 +0000
>>Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>>Muttley@dastardlyhq.com writes:
>>>
>>>[...]
>>>
>>>> "Once all waiting threads have been unblocked (as by the
>>>> pthread_cond_broadcast() operation), the next wait operation on that
>>>condition
>>>> variable shall form a new dynamic binding with the mutex specified by that
>>>wait
>>>> operation. Even though the dynamic binding between condition variable and
>>>mutex
>>>> may be removed or replaced between the time a thread is unblocked from a
>>>wait on
>>>> the condition variable blah blah blah ....."
>>>>
>>>> I'm not sure what your definition of "clear" is but its obviously very
>>>different
>>>> to mine.
>>>
>>>This seems clear to me: Assuming a condition variable c is initially
>>>idle, ie, there are not threads waiting on in, the mutex m used in the
>>>first call to pthread_cond_wait on c must be recorded somewhere to
>>>enable woken-up threads to acquire the correct mutex. A new mutex mm can be
>>>associated with c once all threads sleeping on c+m have been woken up. But
>>>this shall not affect threads which haven't yet returned to the caller
>>>which slept on c while it was still associated with m.
>>
>>No.
>>
>>Clear would be:
>>
>>"Once the thread is woken up on the condition variable it then waits on
>>the mutex AND DOES NOT EXIT pthread_cond_wait() until it aquires it."
>>
>>That is clarity, not the technogibberish above.
>
>The paragraph you call technogibberish has nothing to do with
>what happens with the mutex, it's more of an internal implementation
>detail and a warning to the implementer and the user of the effects of using a
>single
>condition variable with different mutexes.
>
>This paragraph:
>
> Upon successful return, the mutex shall have been locked and
> shall be owned by the calling thread.

That also describe the behaviour with signal.

>Is clear and states exactly what you said "clear would be" above.

Its as clear as mud. If people like you write man pages it explains a lot.

Re: Whats the point of pthread_cond_broadcast() ?

<87h6vubv5m.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10735&group=comp.unix.programmer#10735

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Thu, 09 Feb 2023 17:33:57 +0000
Lines: 50
Message-ID: <87h6vubv5m.fsf@doppelsaurus.mobileactivedefense.com>
References: <trqgmc$312l3$1@dont-email.me>
<5q1abj-n2q.ln1@paranoia.mcleod-schmidt.id.au>
<trts7n$3q3jn$1@dont-email.me> <y3vEL.624380$iU59.162684@fx14.iad>
<trtviq$3qo84$1@dont-email.me> <20230207110711.41@kylheku.com>
<trvpl0$48dj$1@dont-email.me>
<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
<ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad>
<ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad>
<ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad>
<ts0l5t$8s8d$1@dont-email.me>
<877cws6p2m.fsf@doppelsaurus.mobileactivedefense.com>
<ts2ea5$kr94$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Ssa87lq8n+qjxJwnmhg63AIhL00tk9wqN21sWYzErpzSpVVEE=
Cancel-Lock: sha1:37VK1VN2YDw73ImDTSm90Ccx7gA= sha1:brXZdACyUqp9nWvze+wl+8o+kMA=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Thu, 9 Feb 2023 17:33 UTC

Muttley@dastardlyhq.com writes:
> On Wed, 08 Feb 2023 17:32:01 +0000
> Rainer Weikusat <rweikusat@talktalk.net> wrote:
>>Muttley@dastardlyhq.com writes:
>>
>>[...]
>>
>>> "Once all waiting threads have been unblocked (as by the
>>> pthread_cond_broadcast() operation), the next wait operation on that
>>condition
>>> variable shall form a new dynamic binding with the mutex specified by that
>>wait
>>> operation. Even though the dynamic binding between condition variable and
>>mutex
>>> may be removed or replaced between the time a thread is unblocked from a
>>wait on
>>> the condition variable blah blah blah ....."
>>>
>>> I'm not sure what your definition of "clear" is but its obviously very
>>different
>>> to mine.
>>
>>This seems clear to me: Assuming a condition variable c is initially
>>idle, ie, there are not threads waiting on in, the mutex m used in the
>>first call to pthread_cond_wait on c must be recorded somewhere to
>>enable woken-up threads to acquire the correct mutex. A new mutex mm can be
>>associated with c once all threads sleeping on c+m have been woken up. But
>>this shall not affect threads which haven't yet returned to the caller
>>which slept on c while it was still associated with m.
>
> No.
>
> Clear would be:
>
> "Once the thread is woken up on the condition variable it then waits on
> the mutex AND DOES NOT EXIT pthread_cond_wait() until it aquires it."
>
> That is clarity, not the technogibberish above.

As Scott Lurndal already mentioned, this a caveat regarding the
implementation of condition variables: The mutex currently associated
with one must be recorded somewhere. The obvious idea would be whatever
data structure is associated with the condition variable. But that's not
sufficent: If a pthread_cond_broadcast call wakes up all threads waiting
on a condition variable, some of them might not get an actual chance to
run before a subsequent pthread_cond_wait call causes a different mutex
to be associated with it. Hence, the mutex at time of the wakeup must be
recorded somewhere where it remains available to the woken-up threads
regardles of the current state of the condition variable.

Re: Whats the point of pthread_cond_broadcast() ?

<87cz6ibv04.fsf@doppelsaurus.mobileactivedefense.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=10736&group=comp.unix.programmer#10736

  copy link   Newsgroups: comp.unix.programmer
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: rweiku...@talktalk.net (Rainer Weikusat)
Newsgroups: comp.unix.programmer
Subject: Re: Whats the point of pthread_cond_broadcast() ?
Date: Thu, 09 Feb 2023 17:37:15 +0000
Lines: 27
Message-ID: <87cz6ibv04.fsf@doppelsaurus.mobileactivedefense.com>
References: <trqgmc$312l3$1@dont-email.me> <trtviq$3qo84$1@dont-email.me>
<20230207110711.41@kylheku.com> <trvpl0$48dj$1@dont-email.me>
<87k00s6w9c.fsf@doppelsaurus.mobileactivedefense.com>
<ts0gdd$8207$1@dont-email.me> <_HPEL.638934$iU59.175216@fx14.iad>
<ts0h68$869b$1@dont-email.me> <IcQEL.127182$Ldj8.119120@fx47.iad>
<ts0jo2$8k6d$1@dont-email.me> <aHQEL.430433$gGD7.95617@fx11.iad>
<ts0l5t$8s8d$1@dont-email.me>
<877cws6p2m.fsf@doppelsaurus.mobileactivedefense.com>
<ts2ea5$kr94$1@dont-email.me> <vH7FL.176892$PXw7.109888@fx45.iad>
<ts3677$ng29$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net hK3okcBWdm5Hnzs5LwTiLQkfqgDmOm73sXeIuOyZp0PPLdsoc=
Cancel-Lock: sha1:jPXTzfiWePGYtrOu1M19l4nPo9U= sha1:1t5cxf6QUDe7rpsFv7W627472SQ=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.1 (gnu/linux)
 by: Rainer Weikusat - Thu, 9 Feb 2023 17:37 UTC

Muttley@dastardlyhq.com writes:
> scott@slp53.sl.home (Scott Lurndal) wrote:
>>Muttley@dastardlyhq.com writes:

[...]

>>>Clear would be:
>>>
>>>"Once the thread is woken up on the condition variable it then waits on
>>>the mutex AND DOES NOT EXIT pthread_cond_wait() until it aquires it."
>>>
>>>That is clarity, not the technogibberish above.
>>
>>The paragraph you call technogibberish has nothing to do with
>>what happens with the mutex, it's more of an internal implementation
>>detail and a warning to the implementer and the user of the effects of using a
>>single
>>condition variable with different mutexes.
>>
>>This paragraph:
>>
>> Upon successful return, the mutex shall have been locked and
>> shall be owned by the calling thread.
>
> That also describe the behaviour with signal.

Obviously, as the behaviour is identical in this regard.

Pages:12
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor