Skip to content

Commit f489b81

Browse files
committed
[ub,intro.progress] Added entry for UB due to lack of forward progress
1 parent 925968d commit f489b81

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

source/basic.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6912,8 +6912,8 @@
69126912
\rSec3[intro.progress]{Forward progress}
69136913

69146914
\pnum
6915-
The implementation may assume that any thread will eventually do one of the
6916-
following:
6915+
The implementation may assume\ubdef{intro.progress.stops} that any thread
6916+
will eventually do one of the following:
69176917
\begin{itemize}
69186918
\item terminate,
69196919
\item invoke the function \tcode{std::this_thread::yield}\iref{thread.thread.this},

source/ub.tex

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -502,6 +502,29 @@
502502
\end{codeblock}
503503
\end{example}
504504

505+
\rsec2[ub.intro.progress]{Forward progress}
506+
507+
\pnum
508+
\ubxref{intro.progress.stops} \\
509+
510+
The behavior is undefined if a thread of execution that has not terminated stops
511+
making execution steps.
512+
513+
\pnum
514+
\begin{example}
515+
\begin{codeblock}
516+
bool stop() { return false; }
517+
518+
void busy_wait_thread() {
519+
while (!stop()); // undefined behavior, thread makes no progress but the loop
520+
} // is not trivial because `stop()` is not a constant expression
521+
522+
int main() {
523+
std::thread t(busy_wait_thread);
524+
t.join();
525+
}
526+
\end{codeblock}
527+
\end{example}
505528

506529
\rSec2[ub.basic.start.main]{main function}
507530

0 commit comments

Comments
 (0)