[PATCH 1/5] pi_stress: Fix inconsistent barrier wait logic to prevent deadlock

John Kacur <[email protected]> Tue, 30 Jun 2026 12:44:58 -0400
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
The low_priority thread function unconditionally waited on the
all_threads_done barrier, while med_priority and high_priority only
waited when have_errors == 0. This inconsistency could cause deadlock
during error conditions where med_priority and high_priority threads
exit without waiting, leaving low_priority threads waiting forever.

Make low_priority consistent with the other thread functions by adding
the same have_errors check before waiting on all_threads_done.

Assisted-by: Claude:claude-sonnet-4-5
Signed-off-by: John Kacur <[email protected]>
---
 src/pi_tests/pi_stress.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/pi_tests/pi_stress.c b/src/pi_tests/pi_stress.c
index 74e7bde0c21f..b7f7515fa9b1 100644
--- a/src/pi_tests/pi_stress.c
+++ b/src/pi_tests/pi_stress.c
@@ -605,13 +605,16 @@ void *low_priority(void *arg)
 	}
 	set_shutdown_flag();
 	pi_debug("low_priority[%d]: entering done barrier\n", p->id);
-	/* wait for all threads to finish */
-	status = pthread_barrier_wait(&all_threads_done);
-	if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) {
-		pi_error
-		    ("low_priority[%d]: pthread_barrier_wait(all_threads_done): %x",
-		     p->id, status);
-		return NULL;
+
+	if (have_errors == 0) {
+		/* wait for all threads to finish */
+		status = pthread_barrier_wait(&all_threads_done);
+		if (status && status != PTHREAD_BARRIER_SERIAL_THREAD) {
+			pi_error
+			    ("low_priority[%d]: pthread_barrier_wait(all_threads_done): %x",
+			     p->id, status);
+			return NULL;
+		}
 	}
 	pi_debug("low_priority[%d]: exiting\n", p->id);
 	return NULL;
-- 
2.54.0