From dfa63778bdca7773fe01a31418ff3981166a59a9 Mon Sep 17 00:00:00 2001 From: Max Krasnyansky Date: Wed, 7 Aug 2024 23:08:31 -0700 Subject: [PATCH] threadpool: do not wakeup threads in already paused threadpool --- ggml/src/ggml.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ggml/src/ggml.c b/ggml/src/ggml.c index 07f8cdf75..989b5d692 100644 --- a/ggml/src/ggml.c +++ b/ggml/src/ggml.c @@ -18891,8 +18891,10 @@ void ggml_pause_threadpool(struct ggml_compute_threadpool * threadpool) { GGML_ASSERT(!threadpool->disposable); GGML_PRINT_DEBUG("Pausing threadpool\n"); ggml_mutex_lock(&threadpool->mutex); - threadpool->pause = true; - ggml_cond_broadcast(&threadpool->cond); + if (!threadpool->pause) { + threadpool->pause = true; + ggml_cond_broadcast(&threadpool->cond); + } ggml_mutex_unlock(&threadpool->mutex); #else UNUSED(threadpool); @@ -18905,8 +18907,10 @@ void ggml_resume_threadpool(struct ggml_compute_threadpool * threadpool) { GGML_PRINT_DEBUG("Resuming threadpool\n"); ggml_mutex_lock(&threadpool->mutex); - threadpool->pause = false; - ggml_cond_broadcast(&threadpool->cond); + if (threadpool->pause) { + threadpool->pause = false; + ggml_cond_broadcast(&threadpool->cond); + } ggml_mutex_unlock(&threadpool->mutex); #else UNUSED(threadpool);