@@ -18937,7 +18937,6 @@ void ggml_release_threadpool(struct ggml_compute_threadpool* threadpool) {
18937
18937
if (!threadpool->disposable) {
18938
18938
ggml_mutex_lock(&threadpool->mutex);
18939
18939
}
18940
- threadpool->n_threads_cur = n_threads;
18941
18940
threadpool->stop = true;
18942
18941
threadpool->pause = false;
18943
18942
if (!threadpool->disposable) {
@@ -19230,21 +19229,27 @@ static thread_ret_t ggml_graph_compute_thread(void * data) {
19230
19229
static bool ggml_graph_compute_check_for_work(struct ggml_compute_state * state) {
19231
19230
struct ggml_compute_threadpool * threadpool = state->threadpool;
19232
19231
19233
- do {
19234
- if (threadpool->poll) {
19235
- while (!threadpool->new_work && !threadpool->stop && !threadpool->pause) {
19236
- // No new work. Yield and keep polling.
19237
- __cpu_relax();
19238
- }
19239
- } else {
19240
- ggml_mutex_lock_shared(&threadpool->mutex);
19241
- while (!threadpool->new_work && !threadpool->stop && !threadpool->pause) {
19242
- // No new work. Wait for the signal.
19243
- ggml_cond_wait(&threadpool->cond, &threadpool->mutex);
19244
- }
19245
- ggml_mutex_unlock_shared(&threadpool->mutex);
19232
+ if (threadpool->poll) {
19233
+ while (!((threadpool->new_work && state->ith < threadpool->n_threads_cur) ||
19234
+ threadpool->stop ||
19235
+ threadpool->pause
19236
+ )
19237
+ ) {
19238
+ // No new work. Yield and keep polling.
19239
+ __cpu_relax();
19246
19240
}
19247
- } while (state->ith >= threadpool->n_threads_cur);
19241
+ } else {
19242
+ ggml_mutex_lock_shared(&threadpool->mutex);
19243
+ while (!((threadpool->new_work && state->ith < threadpool->n_threads_cur) ||
19244
+ threadpool->stop ||
19245
+ threadpool->pause
19246
+ )
19247
+ ) {
19248
+ // No new work. Wait for the signal.
19249
+ ggml_cond_wait(&threadpool->cond, &threadpool->mutex);
19250
+ }
19251
+ ggml_mutex_unlock_shared(&threadpool->mutex);
19252
+ }
19248
19253
return threadpool->new_work;
19249
19254
}
19250
19255
0 commit comments