1. Abstract
Add a
function to classes
and
, which returns the maximum number of threads that the implementation supports arriving at the
or
.
2. Motivation
Both
([thread.latch]) and
([thread.barrier]) have a constructor that takes a
parameter that indicates how many threads need to arrive at the latch or barrier before waiting threads are unblocked. The constructors in both classes require that
be non-negative. But they don’t place any upper limit on the value of the argument. It is well-formed for a program to create a latch or barrier with an expected count of
. It is unlikely that an implementation could support that in a useful way.
Implementations of
and
can have better performance without sacrificing any usefulness if the implementor is allowed to limit the expected count.
3. Wording
3.1. class latch
Change the beginning of the class summary in 32.8.3 "Class
" [thread.latch.class] as follows:
namespace std { class latch { public : static constexpr ptrdiff_t max () noexcept ; constexpr explicit latch ( ptrdiff_t expected ); // ...
Insert the following after paragraph 2 (just before the constructor) in [thread.latch.class]:
static constexpr ptrdiff_t max () noexcept ; Returns: The maximum value of
that the implementation supports.
counter
Change the description of the constructor in [thread.latch.class] as follows:
constexpr explicit latch ( ptrdiff_t expected ); Expects:
is
expected >= 0 true
andis
expected <= max () true
.Effects: Initializes
with
counter .
expected Throws: Nothing.
3.2. class barrier
Change the beginning of the class summary in 32.8.4.2 "Class template
" [thread.barrier.class] as follows:
namespace std { template < class CompletionFunction = see below > class barrier { public : using arrival_token = see below ; static constexpr ptrdiff_t max () noexcept ; constexpr explicit barrier ( ptrdiff_t expected , CompletionFunction f = CompletionFunction ()); // ...
Insert the following just after paragraph 7 (just before the constructor) in [thread.barrier.class]:
static constexpr ptrdiff_t max () noexcept ; Returns: The maximum expected count that the implementation supports.
Change the description of the constructor in [thread.barrier.class] as follows:
constexpr explicit barrier ( ptrdiff_t expected , CompletionFunction f = CompletionFunction ()); Expects:
is
expected >= 0 true
andis
expected <= max () true
.Effects: Sets both the initial expected count for each barrier phase and the current expected count for the first phase to
. Initializes
expected with
completion . Starts the first phase. [Note: If
std :: move ( f ) is 0 this object can only be destroyed. -- end note ]
expected Throws: Any exception thrown by
's move constructor.
CompletionFunction