Liste des Groupes | Revenir à cl c++ |
On Wed, 11 Sep 2024 07:37:13 -070010 is the maximum count the semaphore is allowed to reach, therefore binary_semaphore, which is an alias-template to counting_semaphore<1>,
Andrey Tarasevich <andreytarasevich@hotmail.com> boringly babbled:On 09/11/24 3:15 AM, Muttley@dastardlyhq.com wrote:It seems I'm not the only one getting confused here. If I write:I've been looking at counting_semaphore and it looks useful but something>
that doesn't seem to be properly explained anywhere is the template
parameter value. eg you can do:
>
std::counting_semaphore sem(2)
>
which will let a max of 2 threads into the protected block at a time or:
No, there's nothing "max" about that 2 here. 2 means that the semaphore
will be created with 2 available "permissions to enter" (permissions to
`acquire()`) initially. The number of available "permissions" can be
increased by calling `release()` after creating the semaphore. Call
`release()` 3 more times on our semaphore right away, and the initial 2
will increase to 5. So, 2 is not "max".
>
The "max" is set by the template parameter `LeastMaxValue`.
std::counting_semaphore<10> sem(2)
then the semaphore can only be aquired TWO times, not 10. I don't understand
what the 10 is supposed to do as changing the 10 to 0,1 or 1000 makes no
difference whatsoever to how many times acquire() can be called before
release() is called in the tests I've done.
Les messages affichés proviennent d'usenet.