From: Kevin Day Date: Tue, 29 Jul 2025 03:19:22 +0000 (-0500) Subject: Bugfix: Final signal thread deadlocks on interrupt. X-Git-Tag: 0.7.3~46 X-Git-Url: https://www.git.kevux.org/?a=commitdiff_plain;h=36f7a8102d3a980fa5a4da18855e6a5133de14a4;p=controller Bugfix: Final signal thread deadlocks on interrupt. This is the same situation as seen in commit 3e9f838e9f67f9bb1a7042e1c24d3f169aa037d7. Set the thread cancel state to `PTHREAD_CANCEL_ASYNCHRONOUS` while waiting for a signal. Set the thread cancel state back to `PTHREAD_CANCEL_DEFERRED,` while not waiting for a signal. --- diff --git a/sources/c/program/controller/main/thread/signal.c b/sources/c/program/controller/main/thread/signal.c index fb633fc..842e1f2 100644 --- a/sources/c/program/controller/main/thread/signal.c +++ b/sources/c/program/controller/main/thread/signal.c @@ -20,8 +20,14 @@ extern "C" { controller_time_now(controller_thread_timeout_exit_ready_seconds_d, controller_thread_timeout_exit_ready_nanoseconds_d, &time); + // Allow thread to be interrupted and auto-cancelled while sleeping. + f_thread_cancel_state_set(PTHREAD_CANCEL_ASYNCHRONOUS, 0); + if (f_signal_wait_until(&main->program.signal.set, &time, &information) == F_time_out) continue; + // Prevent thread from being interrupted and auto-cancelled. + f_thread_cancel_state_set(PTHREAD_CANCEL_DEFERRED, 0); + if (information.si_signo == F_signal_interrupt || information.si_signo == F_signal_abort || information.si_signo == F_signal_quit || information.si_signo == F_signal_termination) { main->thread.signal = information.si_signo;