From 5a02743c0c9563f41a8c3821a7bbce4fc3b0b839 Mon Sep 17 00:00:00 2001 From: Aargh Rai Date: Thu, 27 Aug 2026 17:41:07 +0530 Subject: bug fixes --- src/main.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/main.c') diff --git a/src/main.c b/src/main.c index 61a3850..f54aa19 100644 --- a/src/main.c +++ b/src/main.c @@ -67,6 +67,9 @@ skip_refresh: break; } if (is_stop) { + // cooperative stop: signal all threads, wait for them to finish + threads_stop_all(&engine_threads); + threads_join(&engine_threads); threads_cleanup(&engine_threads); ipc_state_set_event(&ipc_state, EVENT_UCI_RUNNING); goto waiting_for_go; @@ -76,6 +79,12 @@ skip_refresh: } quit: + // cooperative stop for engine threads, then hard-cancel the UCI thread + // (which blocks on stdin and cannot exit cooperatively). + if (engine_threads.running_count > 0) { + threads_stop_all(&engine_threads); + threads_join(&engine_threads); + } ipc_state_deinit(&ipc_state); pthread_cancel(uci_thread); threads_deinit(&engine_threads); -- cgit v1.2.3