Init
This commit is contained in:
310
cppdraft/thread/barrier/class.md
Normal file
310
cppdraft/thread/barrier/class.md
Normal file
@@ -0,0 +1,310 @@
|
||||
[thread.barrier.class]
|
||||
|
||||
# 32 Concurrency support library [[thread]](./#thread)
|
||||
|
||||
## 32.9 Coordination types [[thread.coord]](thread.coord#thread.barrier.class)
|
||||
|
||||
### 32.9.3 Barriers [[thread.barrier]](thread.barrier#class)
|
||||
|
||||
#### 32.9.3.3 Class template barrier [thread.barrier.class]
|
||||
|
||||
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()); ~barrier();
|
||||
|
||||
barrier(const barrier&) = delete;
|
||||
barrier& operator=(const barrier&) = delete;
|
||||
|
||||
arrival_token arrive(ptrdiff_t update = 1); void wait(arrival_token&& arrival) const; void arrive_and_wait(); void arrive_and_drop(); private: CompletionFunction completion; // *exposition only*};}
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10895)
|
||||
|
||||
Each [*barrier phase*](#def:barrier_phase "32.9.3.3 Class template barrier [thread.barrier.class]") consists of the following steps:
|
||||
|
||||
- [(1.1)](#1.1)
|
||||
|
||||
The expected count is decremented
|
||||
by each call to arrive or arrive_and_drop[.](#1.1.sentence-1)
|
||||
|
||||
- [(1.2)](#1.2)
|
||||
|
||||
Exactly once after the expected count reaches zero, a thread
|
||||
executes the completion step during its call
|
||||
to arrive, arrive_and_drop, or wait,
|
||||
except that it is implementation-defined
|
||||
whether the step executes if no thread calls wait[.](#1.2.sentence-1)
|
||||
|
||||
- [(1.3)](#1.3)
|
||||
|
||||
When the completion step finishes,
|
||||
the expected count is reset
|
||||
to what was specified by the expected argument to the constructor,
|
||||
possibly adjusted by calls to arrive_and_drop, and
|
||||
the next phase starts[.](#1.3.sentence-1)
|
||||
|
||||
[2](#2)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10916)
|
||||
|
||||
Each phase defines a [*phase synchronization point*](#def:barrier,phase_synchronization_point "32.9.3.3 Class template barrier [thread.barrier.class]")[.](#2.sentence-1)
|
||||
|
||||
Threads that arrive at the barrier during the phase
|
||||
can block on the phase synchronization point by calling wait, and
|
||||
will remain blocked until the phase completion step is run[.](#2.sentence-2)
|
||||
|
||||
[3](#3)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10923)
|
||||
|
||||
The [*phase completion step*](#def:phase_completion_step "32.9.3.3 Class template barrier [thread.barrier.class]") that is executed at the end of each phase has the following effects:
|
||||
|
||||
- [(3.1)](#3.1)
|
||||
|
||||
Invokes the completion function, equivalent to completion()[.](#3.1.sentence-1)
|
||||
|
||||
- [(3.2)](#3.2)
|
||||
|
||||
Unblocks all threads that are blocked on the phase synchronization point[.](#3.2.sentence-1)
|
||||
|
||||
The end of the completion step strongly happens before
|
||||
the returns from all calls that were unblocked by the completion step[.](#3.sentence-2)
|
||||
|
||||
For specializations that do not have
|
||||
the default value of the CompletionFunction template parameter,
|
||||
the behavior is undefined if any of the barrier object's member functions
|
||||
other than wait are called while the completion step is in progress[.](#3.sentence-3)
|
||||
|
||||
[4](#4)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10937)
|
||||
|
||||
Concurrent invocations of the member functions of barrier,
|
||||
other than its destructor, do not introduce data races[.](#4.sentence-1)
|
||||
|
||||
The member functions arrive and arrive_and_drop execute atomically[.](#4.sentence-2)
|
||||
|
||||
[5](#5)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10943)
|
||||
|
||||
CompletionFunction shall meet the[*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")) and[*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements")) requirements[.](#5.sentence-1)
|
||||
|
||||
is_nothrow_invocable_v<CompletionFunction&> shall be true[.](#5.sentence-2)
|
||||
|
||||
[6](#6)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10949)
|
||||
|
||||
The default value of the CompletionFunction template parameter is
|
||||
an unspecified type, such that,
|
||||
in addition to satisfying the requirements of CompletionFunction,
|
||||
it meets the [*Cpp17DefaultConstructible*](utility.arg.requirements#:Cpp17DefaultConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") requirements (Table [30](utility.arg.requirements#tab:cpp17.defaultconstructible "Table 30: Cpp17DefaultConstructible requirements")) andcompletion() has no effects[.](#6.sentence-1)
|
||||
|
||||
[7](#7)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10957)
|
||||
|
||||
barrier::arrival_token is an unspecified type,
|
||||
such that it meets the[*Cpp17MoveConstructible*](utility.arg.requirements#:Cpp17MoveConstructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [31](utility.arg.requirements#tab:cpp17.moveconstructible "Table 31: Cpp17MoveConstructible requirements")),[*Cpp17MoveAssignable*](utility.arg.requirements#:Cpp17MoveAssignable "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [33](utility.arg.requirements#tab:cpp17.moveassignable "Table 33: Cpp17MoveAssignable requirements")), and[*Cpp17Destructible*](utility.arg.requirements#:Cpp17Destructible "16.4.4.2 Template argument requirements [utility.arg.requirements]") (Table [35](utility.arg.requirements#tab:cpp17.destructible "Table 35: Cpp17Destructible requirements")) requirements[.](#7.sentence-1)
|
||||
|
||||
[ð](#lib:max,barrier)
|
||||
|
||||
`static constexpr ptrdiff_t max() noexcept;
|
||||
`
|
||||
|
||||
[8](#8)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10970)
|
||||
|
||||
*Returns*: The maximum expected count that the implementation supports[.](#8.sentence-1)
|
||||
|
||||
[ð](#lib:barrier,constructor)
|
||||
|
||||
`constexpr explicit barrier(ptrdiff_t expected,
|
||||
CompletionFunction f = CompletionFunction());
|
||||
`
|
||||
|
||||
[9](#9)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10982)
|
||||
|
||||
*Preconditions*: expected >= 0 is true andexpected <= max() is true[.](#9.sentence-1)
|
||||
|
||||
[10](#10)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10987)
|
||||
|
||||
*Effects*: Sets both the initial expected count for each barrier phase and
|
||||
the current expected count for the first phase to expected[.](#10.sentence-1)
|
||||
|
||||
Initializes completion with std::move(f)[.](#10.sentence-2)
|
||||
|
||||
Starts the first phase[.](#10.sentence-3)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
If expected is 0 this object can only be destroyed[.](#10.sentence-4)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[11](#11)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10997)
|
||||
|
||||
*Throws*: Any exception thrown by CompletionFunction's move constructor[.](#11.sentence-1)
|
||||
|
||||
[ð](#lib:arrive,barrier)
|
||||
|
||||
`arrival_token arrive(ptrdiff_t update = 1);
|
||||
`
|
||||
|
||||
[12](#12)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11008)
|
||||
|
||||
*Preconditions*: update > 0 is true, andupdate is less than or equal to
|
||||
the expected count for the current barrier phase[.](#12.sentence-1)
|
||||
|
||||
[13](#13)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11014)
|
||||
|
||||
*Effects*: Constructs an object of type arrival_token that is associated with the phase synchronization point for the current phase[.](#13.sentence-1)
|
||||
|
||||
Then, decrements the expected count by update[.](#13.sentence-2)
|
||||
|
||||
[14](#14)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11020)
|
||||
|
||||
*Synchronization*: The call to arrive strongly happens before
|
||||
the start of the phase completion step for the current phase[.](#14.sentence-1)
|
||||
|
||||
[15](#15)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11025)
|
||||
|
||||
*Returns*: The constructed arrival_token object[.](#15.sentence-1)
|
||||
|
||||
[16](#16)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11029)
|
||||
|
||||
*Throws*: system_error when an exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#16.sentence-1)
|
||||
|
||||
[17](#17)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11033)
|
||||
|
||||
*Error conditions*: Any of the error conditions
|
||||
allowed for mutex types ([[thread.mutex.requirements.mutex]](thread.mutex.requirements.mutex "32.6.4.2 Mutex types"))[.](#17.sentence-1)
|
||||
|
||||
[18](#18)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11038)
|
||||
|
||||
[*Note [2](#note-2)*:
|
||||
|
||||
This call can cause the completion step for the current phase to start[.](#18.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[ð](#lib:wait,barrier)
|
||||
|
||||
`void wait(arrival_token&& arrival) const;
|
||||
`
|
||||
|
||||
[19](#19)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11050)
|
||||
|
||||
*Preconditions*: arrival is associated with
|
||||
the phase synchronization point for the current phase or
|
||||
the immediately preceding phase of the same barrier object[.](#19.sentence-1)
|
||||
|
||||
[20](#20)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11056)
|
||||
|
||||
*Effects*: Blocks at the synchronization point associated with std::move(arrival) until the phase completion step of the synchronization point's phase is run[.](#20.sentence-1)
|
||||
|
||||
[*Note [3](#note-3)*:
|
||||
|
||||
If arrival is associated with the synchronization point
|
||||
for a previous phase, the call returns immediately[.](#20.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
|
||||
[21](#21)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11066)
|
||||
|
||||
*Throws*: system_error when an exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#21.sentence-1)
|
||||
|
||||
[22](#22)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11070)
|
||||
|
||||
*Error conditions*: Any of the error conditions
|
||||
allowed for mutex types ([[thread.mutex.requirements.mutex]](thread.mutex.requirements.mutex "32.6.4.2 Mutex types"))[.](#22.sentence-1)
|
||||
|
||||
[ð](#lib:arrive_and_wait,barrier)
|
||||
|
||||
`void arrive_and_wait();
|
||||
`
|
||||
|
||||
[23](#23)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11082)
|
||||
|
||||
*Effects*: Equivalent to: wait(arrive())[.](#23.sentence-1)
|
||||
|
||||
[ð](#lib:arrive_and_drop,barrier)
|
||||
|
||||
`void arrive_and_drop();
|
||||
`
|
||||
|
||||
[24](#24)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11093)
|
||||
|
||||
*Preconditions*: The expected count for the current barrier phase is greater than zero[.](#24.sentence-1)
|
||||
|
||||
[25](#25)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11097)
|
||||
|
||||
*Effects*: Decrements the initial expected count for all subsequent phases by one[.](#25.sentence-1)
|
||||
|
||||
Then decrements the expected count for the current phase by one[.](#25.sentence-2)
|
||||
|
||||
[26](#26)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11102)
|
||||
|
||||
*Synchronization*: The call to arrive_and_drop strongly happens before
|
||||
the start of the phase completion step for the current phase[.](#26.sentence-1)
|
||||
|
||||
[27](#27)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11107)
|
||||
|
||||
*Throws*: system_error when an exception is required ([[thread.req.exception]](thread.req.exception "32.2.2 Exceptions"))[.](#27.sentence-1)
|
||||
|
||||
[28](#28)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11111)
|
||||
|
||||
*Error conditions*: Any of the error conditions
|
||||
allowed for mutex types ([[thread.mutex.requirements.mutex]](thread.mutex.requirements.mutex "32.6.4.2 Mutex types"))[.](#28.sentence-1)
|
||||
|
||||
[29](#29)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L11116)
|
||||
|
||||
[*Note [4](#note-4)*:
|
||||
|
||||
This call can cause the completion step for the current phase to start[.](#29.sentence-1)
|
||||
|
||||
â *end note*]
|
||||
25
cppdraft/thread/barrier/general.md
Normal file
25
cppdraft/thread/barrier/general.md
Normal file
@@ -0,0 +1,25 @@
|
||||
[thread.barrier.general]
|
||||
|
||||
# 32 Concurrency support library [[thread]](./#thread)
|
||||
|
||||
## 32.9 Coordination types [[thread.coord]](thread.coord#thread.barrier.general)
|
||||
|
||||
### 32.9.3 Barriers [[thread.barrier]](thread.barrier#general)
|
||||
|
||||
#### 32.9.3.1 General [thread.barrier.general]
|
||||
|
||||
[1](#1)
|
||||
|
||||
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/threads.tex#L10845)
|
||||
|
||||
A barrier is a thread coordination mechanism
|
||||
whose lifetime consists of a sequence of barrier phases,
|
||||
where each phase allows at most an expected number of threads to block
|
||||
until the expected number of threads arrive at the barrier[.](#1.sentence-1)
|
||||
|
||||
[*Note [1](#note-1)*:
|
||||
|
||||
A barrier is useful for managing repeated tasks
|
||||
that are handled by multiple threads[.](#1.sentence-2)
|
||||
|
||||
â *end note*]
|
||||
Reference in New Issue
Block a user