summaryrefslogtreecommitdiff
path: root/src/main.c
diff options
context:
space:
mode:
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);