Skip to content

Commit e8a9120

Browse files
authored
Merge 2023-02 LWG Motion 19
P2588R3 barrier's phase completion guarantees
2 parents d4cf9a4 + 3600bc3 commit e8a9120

File tree

3 files changed

+40
-10
lines changed

3 files changed

+40
-10
lines changed

source/compatibility.tex

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,40 @@
322322
};
323323
\end{codeblock}
324324

325+
\rSec2[diff.cpp20.thread]{\ref{thread}: concurrency support library}
326+
327+
\diffref{thread.barrier}
328+
\change
329+
In this revision of \Cpp{},
330+
it is implementation-defined whether a barrier's phase completion step runs
331+
if no thread calls \tcode{wait}.
332+
Previously the phase completion step was guaranteed to run on the last thread that calls \tcode{arrive} or \tcode{arrive_and_drop} during the phase.
333+
In this revision of \Cpp{},
334+
it can run on any of the threads that arrived or waited at the barrier
335+
during the phase.
336+
\rationale
337+
Correct contradictory wording and
338+
improve implementation flexibility for performance.
339+
\effect
340+
Valid \CppXX{} code using a barrier might have
341+
different semantics in this revision of \Cpp{}
342+
if it depends on a completion function's side effects occurring exactly once,
343+
on a specific thread running the phase completion step, or
344+
on a completion function's side effects occurring
345+
without \tcode{wait} having been called.
346+
For example:
347+
\begin{codeblock}
348+
auto b0 = std::barrier(1);
349+
b0.arrive();
350+
b0.arrive(); // implementation-defined; previously well-defined
351+
352+
int data = 0;
353+
auto b1 = std::barrier(1, [&] { data++; });
354+
b1.arrive();
355+
assert(data == 1); // implementation-defined; previously well-defined
356+
b1.arrive(); // implementation-defined; previously well-defined
357+
\end{codeblock}
358+
325359
\rSec1[diff.cpp17]{\Cpp{} and ISO \CppXVII{}}
326360

327361
\rSec2[diff.cpp17.general]{General}

source/support.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -573,7 +573,7 @@
573573
#define @\defnlibxname{cpp_lib_atomic_shared_ptr}@ 201711L // also in \libheader{memory}
574574
#define @\defnlibxname{cpp_lib_atomic_value_initialization}@ 201911L // also in \libheader{atomic}, \libheader{memory}
575575
#define @\defnlibxname{cpp_lib_atomic_wait}@ 201907L // also in \libheader{atomic}
576-
#define @\defnlibxname{cpp_lib_barrier}@ 201907L // also in \libheader{barrier}
576+
#define @\defnlibxname{cpp_lib_barrier}@ 202302L // also in \libheader{barrier}
577577
#define @\defnlibxname{cpp_lib_bind_back}@ 202202L // also in \libheader{functional}
578578
#define @\defnlibxname{cpp_lib_bind_front}@ 201907L // also in \libheader{functional}
579579
#define @\defnlibxname{cpp_lib_bit_cast}@ 201806L // also in \libheader{bit}

source/threads.tex

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9643,15 +9643,11 @@
96439643
The expected count is decremented
96449644
by each call to \tcode{arrive} or \tcode{arrive_and_drop}.
96459645
\item
9646-
When the expected count reaches zero, the phase completion step is run.
9647-
For the specialization
9648-
with the default value of the \tcode{CompletionFunction} template parameter,
9649-
the completion step is run
9650-
as part of the call to \tcode{arrive} or \tcode{arrive_and_drop}
9651-
that caused the expected count to reach zero.
9652-
For other specializations,
9653-
the completion step is run on one of the threads
9654-
that arrived at the barrier during the phase.
9646+
Exactly once after the expected count reaches zero, a thread
9647+
executes the completion step during its call
9648+
to \tcode{arrive}, \tcode{arrive_and_drop}, or \tcode{wait},
9649+
except that it is \impldef{barrier phrase completion without \tcode{wait}}
9650+
whether the step executes if no thread calls \tcode{wait}.
96559651
\item
96569652
When the completion step finishes,
96579653
the expected count is reset

0 commit comments

Comments
 (0)