From e882f3d6f3362c0a1288e9b5d294690edf674f1c Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 9 Sep 2017 18:58:38 +0200 Subject: [PATCH 1/3] Fix thread data race in memory.c --- driver/others/memory.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/driver/others/memory.c b/driver/others/memory.c index 661f7c4ebb..a32d188340 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -1075,12 +1075,13 @@ void *blas_memory_alloc(int procpos){ do { /* if (!memory[position].used) { */ - - blas_lock(&memory[position].lock); + LOCK_COMMAND(&alloc_lock); +/* blas_lock(&memory[position].lock);*/ if (!memory[position].used) goto allocation; - - blas_unlock(&memory[position].lock); + + UNLOCK_COMMAND(&alloc_lock); +/* blas_unlock(&memory[position].lock);*/ /* } */ position ++; @@ -1097,7 +1098,8 @@ void *blas_memory_alloc(int procpos){ memory[position].used = 1; - blas_unlock(&memory[position].lock); + UNLOCK_COMMAND(&alloc_lock); +/* blas_unlock(&memory[position].lock);*/ if (!memory[position].addr) { do { From f460776f0f8f6ade96dbd1757538667f41afb461 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 9 Sep 2017 19:07:06 +0200 Subject: [PATCH 2/3] 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 9debe178d2..2e0fe190d7 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); From ba1f91f17b3acd76456865cc01218857ac20b072 Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Sat, 9 Sep 2017 20:30:33 +0200 Subject: [PATCH 3/3] Convert another caller of "allocation" to LOCK_COMMAND ... as the "allocation" code jumped to now does UNLOCK_COMMAND instead of blas_unlock --- driver/others/memory.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/driver/others/memory.c b/driver/others/memory.c index a32d188340..a4d26b0e1f 100644 --- a/driver/others/memory.c +++ b/driver/others/memory.c @@ -1056,12 +1056,13 @@ void *blas_memory_alloc(int procpos){ do { if (!memory[position].used && (memory[position].pos == mypos)) { - - blas_lock(&memory[position].lock); + LOCK_COMMAND(&alloc_lock); +/* blas_lock(&memory[position].lock);*/ if (!memory[position].used) goto allocation; - blas_unlock(&memory[position].lock); + UNLOCK_COMMAND(&alloc_lock); +/* blas_unlock(&memory[position].lock);*/ } position ++;