Skip to content

Commit f460776

Browse files
authored
Fix thread data races
1 parent e882f3d commit f460776

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

driver/others/blas_server.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -669,9 +669,15 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
669669
} while (1);
670670

671671
} else {
672-
while(thread_status[i].queue) {
672+
pthread_mutex_lock (&thread_status[i].lock);
673+
tsiq = thread_status[i].queue;
674+
pthread_mutex_unlock (&thread_status[i].lock);
675+
while(tsiq) {
673676
i ++;
674677
if (i >= blas_num_threads - 1) i = 0;
678+
pthread_mutex_lock (&thread_status[i].lock);
679+
tsiq = thread_status[i].queue;
680+
pthread_mutex_unlock (&thread_status[i].lock);
675681
}
676682
}
677683
#else
@@ -960,14 +966,10 @@ int BLASFUNC(blas_thread_shutdown)(void){
960966

961967
for (i = 0; i < blas_num_threads - 1; i++) {
962968

963-
blas_lock(&exec_queue_lock);
969+
pthread_mutex_lock (&thread_status[i].lock);
964970

965971
thread_status[i].queue = (blas_queue_t *)-1;
966972

967-
blas_unlock(&exec_queue_lock);
968-
969-
pthread_mutex_lock (&thread_status[i].lock);
970-
971973
thread_status[i].status = THREAD_STATUS_WAKEUP;
972974

973975
pthread_cond_signal (&thread_status[i].wakeup);

0 commit comments

Comments
 (0)