From 481c6d517b4f9a19dafa44f5084294f8b11fef72 Mon Sep 17 00:00:00 2001 From: mqy Date: Mon, 17 Apr 2023 18:40:54 +0800 Subject: [PATCH] Fixed a segment fault when n_threads == 1 and GGML_GLOBAL_THREADS is defined --- ggml.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/ggml.c b/ggml.c index c7b1901ca..c42c395a1 100644 --- a/ggml.c +++ b/ggml.c @@ -10273,11 +10273,13 @@ void ggml_graph_compute(struct ggml_context * ctx, struct ggml_cgraph * cgraph) } #ifdef GGML_GLOBAL_THREADS - // wakeup threads. - pthread_mutex_lock(&state_shared->mutex); - state_shared->wait_cmd = false; - pthread_cond_broadcast(&state_shared->cond); - pthread_mutex_unlock(&state_shared->mutex); + if (n_threads > 1) { + // wakeup threads. + pthread_mutex_lock(&state_shared->mutex); + state_shared->wait_cmd = false; + pthread_cond_broadcast(&state_shared->cond); + pthread_mutex_unlock(&state_shared->mutex); + } #endif #ifdef GGML_PERF