From 4083ef2f6b959a829ad4b1f049cd6de1b9e0fca8 Mon Sep 17 00:00:00 2001 From: Mark Seminatore Date: Tue, 27 Jun 2023 16:26:41 -0700 Subject: [PATCH] restore lock in exec_blas_async to prevent race on queue --- driver/others/blas_server_win32.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/driver/others/blas_server_win32.c b/driver/others/blas_server_win32.c index 0b213bf2c..580ff8790 100644 --- a/driver/others/blas_server_win32.c +++ b/driver/others/blas_server_win32.c @@ -75,6 +75,7 @@ int blas_server_avail = 0; /* Local Variables */ static BLASULONG server_lock = 0; +static BLASULONG pool_lock = 0; static blas_pool_t pool; static HANDLE blas_threads [MAX_CPU_NUMBER]; static DWORD blas_threads_id[MAX_CPU_NUMBER]; @@ -420,7 +421,17 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){ pos ++; } - pool.queue = queue; +LOCK_COMMAND(&pool_lock); + + if (pool.queue) { + current = pool.queue; + while (current -> next) current = current -> next; + current -> next = queue; + } else { + pool.queue = queue; + } + +UNLOCK_COMMAND(&pool_lock); // start up worker threads ReleaseSemaphore(pool.taskSemaphore, pos - 1, NULL);