From f460776f0f8f6ade96dbd1757538667f41afb461 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 9 Sep 2017 19:07:06 +0200 Subject: [PATCH] Fix thread data races --- driver/others/blas_server.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/driver/others/blas_server.c b/driver/others/blas_server.c index 9debe178d..2e0fe190d 100644 --- a/driver/others/blas_server.c +++ b/driver/others/blas_server.c @@ -669,9 +669,15 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){ } while (1); } else { - while(thread_status[i].queue) { + pthread_mutex_lock (&thread_status[i].lock); + tsiq = thread_status[i].queue; + pthread_mutex_unlock (&thread_status[i].lock); + while(tsiq) { i ++; if (i >= blas_num_threads - 1) i = 0; + pthread_mutex_lock (&thread_status[i].lock); + tsiq = thread_status[i].queue; + pthread_mutex_unlock (&thread_status[i].lock); } } #else @@ -960,14 +966,10 @@ int BLASFUNC(blas_thread_shutdown)(void){ for (i = 0; i < blas_num_threads - 1; i++) { - blas_lock(&exec_queue_lock); + pthread_mutex_lock (&thread_status[i].lock); thread_status[i].queue = (blas_queue_t *)-1; - blas_unlock(&exec_queue_lock); - - pthread_mutex_lock (&thread_status[i].lock); - thread_status[i].status = THREAD_STATUS_WAKEUP; pthread_cond_signal (&thread_status[i].wakeup);