[PATCH stalld 40/52] stalld: check pthread_create return in conservative_main

Wander Lairson Costa <[email protected]> Mon, 8 Jun 2026 15:31:50 -0300
Newsgroups org.kernel.vger.linux-rt-users
Message-ID <[email protected]>
conservative_main() does not check whether pthread_create() succeeds.
On failure, thread_running stays set to one with no thread behind it,
so the main loop permanently skips that CPU on every subsequent cycle.

Capture the return value and, on failure, clear thread_running and log
a warning so monitoring can resume on the next iteration.

Signed-off-by: Wander Lairson Costa <[email protected]>
---
 src/stalld.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/stalld.c b/src/stalld.c
index 049e5f0..0edb30c 100644
--- a/src/stalld.c
+++ b/src/stalld.c
@@ -908,7 +908,11 @@ void conservative_main(struct cpu_info *cpus, int nr_cpus)
 			if (check_might_starve_tasks(cpu)) {
 				cpus[i].id = i;
 				cpus[i].thread_running = 1;
-				pthread_create(&cpus[i].thread, &dettached, cpu_main, &cpus[i]);
+				retval = pthread_create(&cpus[i].thread, &dettached, cpu_main, &cpus[i]);
+				if (retval) {
+					cpus[i].thread_running = 0;
+					warn("%s: pthread_create() failed: %d\n", __func__, retval);
+				}
 			}
 		}
 
-- 
2.54.0