Re: counting_semaphore question

Liste des GroupesRevenir à cl c++ 
Sujet : Re: counting_semaphore question
De : ben (at) *nospam* bsb.me.uk (Ben Bacarisse)
Groupes : comp.lang.c++
Date : 12. Sep 2024, 12:25:07
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <87ikv1i2yk.fsf@bsb.me.uk>
References : 1 2 3 4 5
User-Agent : Gnus/5.13 (Gnus v5.13)
Muttley@dastardlyhq.com writes:

On Wed, 11 Sep 2024 14:10:05 +0200
Bonita Montero <Bonita.Montero@gmail.com> boringly babbled:
Am 11.09.2024 um 14:03 schrieb Muttley@dastardlyhq.com:
>
What upper limit? The max number of threads allowed in the protected section
above is 2, not 10. Or do you mean it'll only count up to 10 threads waiting
and ignore any beyond that? What happens if thread 11 comes along?
>
The static parmeter is the maximum counter and the the two is the
initial counter. So two threads can currently acquire that semaphore.
>
Sorry, I still don't get it. What do you mean by maximum counter?

You might want to consider who you are talking to.

Let's take std::counting_semaphore<M> sem(N); as an example.  The N is
the important number but it is not a 'maximum' in any hard sense -- it
is simply the initial value of the counter.  If it were some sort of
hard maximum, std::counting_semaphore sem(0); would be useless but it
isn't -- it simply means that at least one release() is needed before an
acquire() won't block.  Of course, if often /does/ represent the
maximum number of threads that can access some resource because the
usual pattern is to use std::counting_semaphore sem(N) with the standard
pattern of every thread calling acquire() and then release().

The template parameter M is very different and rather unusual.  It is,
first and foremost, just a hint to the implementation about how much
space will be needed for the counter, so the most useful value for M is
1 because some systems can implement binary semaphores more efficiently
than counting ones.

But this "limit" is not enforced other than by making the behaviour
undefined when it is exceeded.  Pre-conditions on the operations state
that the counter must always be >= 0 and <= M, but you won't be able to
check this unless the implementation decides to enforce these
pre-conditions with some sort of error report.

--
Ben.

Date Sujet#  Auteur
11 Sep 24 * counting_semaphore question78Muttley
11 Sep 24 +* Re: counting_semaphore question63Bonita Montero
11 Sep 24 i`* Re: counting_semaphore question62Muttley
11 Sep 24 i `* Re: counting_semaphore question61Bonita Montero
11 Sep 24 i  +* Re: counting_semaphore question27Muttley
11 Sep 24 i  i+* Re: counting_semaphore question2Bonita Montero
11 Sep 24 i  ii`- Re: counting_semaphore question1Muttley
11 Sep 24 i  i+* Re: counting_semaphore question10David Brown
16 Sep23:22 i  ii`* Re: counting_semaphore question9Chris M. Thomasson
17 Sep09:22 i  ii `* Re: counting_semaphore question8David Brown
17 Sep20:56 i  ii  `* Re: counting_semaphore question7Chris M. Thomasson
18 Sep09:32 i  ii   `* Re: counting_semaphore question6David Brown
19 Sep12:57 i  ii    `* Re: counting_semaphore question5Bonita Montero
19 Sep13:01 i  ii     +- Re: counting_semaphore question1Bonita Montero
19 Sep21:09 i  ii     +- Re: counting_semaphore question1Chris M. Thomasson
19 Sep22:27 i  ii     `* Re: counting_semaphore question2Chris M. Thomasson
19 Sep22:30 i  ii      `- Re: counting_semaphore question1Chris M. Thomasson
12 Sep 24 i  i`* Re: counting_semaphore question14Ben Bacarisse
12 Sep 24 i  i `* Re: counting_semaphore question13Muttley
12 Sep 24 i  i  `* Re: counting_semaphore question12Andrey Tarasevich
12 Sep 24 i  i   `* Re: counting_semaphore question11Muttley
13 Sep 24 i  i    +* Re: counting_semaphore question9David Brown
13 Sep 24 i  i    i`* Re: counting_semaphore question8Muttley
13 Sep 24 i  i    i `* Re: counting_semaphore question7David Brown
13 Sep 24 i  i    i  `* Re: counting_semaphore question6Muttley
13 Sep 24 i  i    i   +* Re: counting_semaphore question3Bonita Montero
13 Sep 24 i  i    i   i+- Re: counting_semaphore question1Muttley
15 Sep17:33 i  i    i   i`- Re: counting_semaphore question1David Brown
13 Sep 24 i  i    i   `* Re: counting_semaphore question2David Brown
13 Sep 24 i  i    i    `- Re: counting_semaphore question1Muttley
13 Sep 24 i  i    `- Re: counting_semaphore question1Andrey Tarasevich
11 Sep 24 i  `* Re: counting_semaphore question33Chris M. Thomasson
12 Sep 24 i   `* Re: counting_semaphore question32Bonita Montero
12 Sep 24 i    `* Re: counting_semaphore question31Chris M. Thomasson
13 Sep 24 i     `* Re: counting_semaphore question30Bonita Montero
13 Sep 24 i      `* Re: counting_semaphore question29Chris M. Thomasson
14 Sep 24 i       `* Re: counting_semaphore question28Bonita Montero
14 Sep 24 i        +* Re: counting_semaphore question2Chris M. Thomasson
14 Sep21:07 i        i`- Re: counting_semaphore question1Chris M. Thomasson
14 Sep11:18 i        `* Re: counting_semaphore question25Muttley
14 Sep11:40 i         `* Re: counting_semaphore question24Bonita Montero
14 Sep12:58 i          +* Re: counting_semaphore question22Muttley
14 Sep13:15 i          i`* Re: counting_semaphore question21Bonita Montero
14 Sep17:13 i          i +* Re: counting_semaphore question12Muttley
14 Sep17:26 i          i i`* Re: counting_semaphore question11Bonita Montero
14 Sep17:48 i          i i `* Re: counting_semaphore question10Muttley
14 Sep17:50 i          i i  `* Re: counting_semaphore question9Bonita Montero
14 Sep17:55 i          i i   `* Re: counting_semaphore question8Muttley
14 Sep17:57 i          i i    `* Re: counting_semaphore question7Bonita Montero
15 Sep11:05 i          i i     `* Re: counting_semaphore question6Muttley
15 Sep11:48 i          i i      `* Re: counting_semaphore question5Bonita Montero
15 Sep11:52 i          i i       `* Re: counting_semaphore question4Muttley
15 Sep14:50 i          i i        `* Re: counting_semaphore question3Bonita Montero
15 Sep17:28 i          i i         `* Re: counting_semaphore question2Muttley
16 Sep05:02 i          i i          `- Re: counting_semaphore question1Bonita Montero
14 Sep21:12 i          i `* Re: counting_semaphore question8Chris M. Thomasson
15 Sep02:21 i          i  +- Re: counting_semaphore question1Chris M. Thomasson
15 Sep07:11 i          i  `* Re: counting_semaphore question6Bonita Montero
15 Sep07:20 i          i   `* Re: counting_semaphore question5Chris M. Thomasson
15 Sep09:35 i          i    `* Re: counting_semaphore question4Bonita Montero
15 Sep21:59 i          i     `* Re: counting_semaphore question3Chris M. Thomasson
16 Sep05:04 i          i      `* Re: counting_semaphore question2Bonita Montero
16 Sep22:30 i          i       `- Re: counting_semaphore question1Chris M. Thomasson
14 Sep21:09 i          `- Re: counting_semaphore question1Chris M. Thomasson
11 Sep 24 `* Re: counting_semaphore question14Andrey Tarasevich
11 Sep 24  `* Re: counting_semaphore question13Muttley
11 Sep 24   +* Re: counting_semaphore question6Bonita Montero
11 Sep 24   i`* Re: counting_semaphore question5Muttley
11 Sep 24   i +* Re: counting_semaphore question3Bonita Montero
11 Sep 24   i i`* Re: counting_semaphore question2Muttley
12 Sep 24   i i `- Re: counting_semaphore question1Bonita Montero
12 Sep 24   i `- Re: counting_semaphore question1Chris M. Thomasson
12 Sep 24   `* Re: counting_semaphore question6Andrey Tarasevich
12 Sep 24    `* Re: counting_semaphore question5Muttley
12 Sep 24     +* Re: counting_semaphore question2David Brown
12 Sep 24     i`- Re: counting_semaphore question1Muttley
12 Sep 24     +- Re: counting_semaphore question1Bonita Montero
12 Sep 24     `- Re: counting_semaphore question1Andrey Tarasevich

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal