summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
authorAargh Rai <aargh.rai+git@gmail.com>2026-08-27 17:41:07 +0530
committerAargh Rai <aargh.rai+git@gmail.com>2026-08-27 17:41:07 +0530
commit5a02743c0c9563f41a8c3821a7bbce4fc3b0b839 (patch)
treef36aa805b8c90a8d786e8561a9d84f57e6191c19 /src/main.c
parentd87b4744bed8f0c43e11ea12508ef2941bdd7186 (diff)
bug fixes
Diffstat (limited to 'src/main.c')
-rw-r--r--src/main.c9
1 files changed, 9 insertions, 0 deletions
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);