Files
2025-10-25 03:02:53 +03:00

47 lines
1.7 KiB
Markdown
Raw Permalink Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[diff.cpp20.thread]
# Annex C (informative) Compatibility [[diff]](./#diff)
## C.2 C++ and ISO C++ 2020 [[diff.cpp20]](diff.cpp20#thread)
### C.2.13 [[thread]](thread "32Concurrency support library"): concurrency support library [diff.cpp20.thread]
[1](#1)
[#](http://github.com/Eelis/draft/tree/9adde4bc1c62ec234483e63ea3b70a59724c745a/source/compatibility.tex#L797)
**Affected subclause:** [[thread.barrier]](thread.barrier)
**Change:** In this revision of C++,
it is implementation-defined whether a barrier's phase completion step runs
if no thread calls wait[.](#1.sentence-1)
Previously the phase completion step was guaranteed to run on the last thread that calls arrive or arrive_and_drop during the phase[.](#1.sentence-2)
In this revision of C++,
it can run on any of the threads that arrived or waited at the barrier
during the phase[.](#1.sentence-3)
**Rationale:** Correct contradictory wording and
improve implementation flexibility for performance[.](#1.sentence-4)
**Effect on original feature:** Valid C++ 2020 code using a barrier might have
different semantics in this revision of C++
if it depends on a completion function's side effects occurring exactly once,
on a specific thread running the phase completion step, or
on a completion function's side effects occurring
without wait having been called[.](#1.sentence-5)
[*Example [1](#example-1)*: auto b0 = std::barrier(1);
b0.arrive();
b0.arrive(); // implementation-defined; previously well-definedint data = 0;auto b1 = std::barrier(1, [&] { data++; });
b1.arrive();
assert(data == 1); // implementation-defined; previously well-defined b1.arrive(); // implementation-defined; previously well-defined — *end example*]