Liste des Groupes | Revenir à cl c++ |
On 09/11/24 3:15 AM, Muttley@dastardlyhq.com wrote: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`.
I don't understand what the '10' will do. Its returned by the max()>
method but whats its purpose since if its the maximum possible threads
you could have in the protected block it makes no sense because you can't
change that value after creation as far as I can see.
The purpose of the template `LeastMaxValue` parameter is to let the
implementation choose the best representation for the internal counter.
Les messages affichés proviennent d'usenet.