From 7a8aef3b5039d65871ec1378f47ebbfd82ada15b Mon Sep 17 00:00:00 2001 From: Levi Neely <141506390+lneely@users.noreply.github.com> Date: Sat, 7 Mar 2026 16:23:48 +0100 Subject: [PATCH] Fix pcl-5xn.1: replace pthread_cond_wait with timedwait in pstatus_wait (#353) Replace indefinite pthread_cond_wait() calls in pstatus_wait() with pthread_cond_timedwait() using a 5-second timeout computed via clock_gettime(CLOCK_REALTIME). On timeout, the while loop re-evaluates the wait condition, preventing indefinite hang when the state machine stalls. Ref GH #292. Co-authored-by: Levi Neely --- pclsync/pstatus.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pclsync/pstatus.c b/pclsync/pstatus.c index fe08d36..f8630b0 100644 --- a/pclsync/pstatus.c +++ b/pclsync/pstatus.c @@ -31,6 +31,7 @@ #include #include +#include #include "pfile.h" #include "pfstasks.h" @@ -266,10 +267,13 @@ void pstatus_set(uint32_t statusid, uint32_t status) { } void pstatus_wait(uint32_t statusid, uint32_t status) { + struct timespec ts; pthread_mutex_lock(&status_internal_mutex); while ((statuses[statusid] & status) == 0 && psync_do_run) { status_waiters++; - pthread_cond_wait(&statuscond, &status_internal_mutex); + clock_gettime(CLOCK_REALTIME, &ts); + ts.tv_sec += 5; + pthread_cond_timedwait(&statuscond, &status_internal_mutex, &ts); status_waiters--; } pthread_mutex_unlock(&status_internal_mutex);