Skip to content

Commit f66d908

Browse files
authored
Merge pull request #1299 from martin-frbg/race_fixes
Fix thread data races uncovered by gcc thread sanitizer
2 parents 00740c0 + ba1f91f commit f66d908

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

driver/others/blas_server.c

+8-6
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);

driver/others/memory.c

+11-8
Original file line numberDiff line numberDiff line change
@@ -1056,12 +1056,13 @@ void *blas_memory_alloc(int procpos){
10561056

10571057
do {
10581058
if (!memory[position].used && (memory[position].pos == mypos)) {
1059-
1060-
blas_lock(&memory[position].lock);
1059+
LOCK_COMMAND(&alloc_lock);
1060+
/* blas_lock(&memory[position].lock);*/
10611061

10621062
if (!memory[position].used) goto allocation;
10631063

1064-
blas_unlock(&memory[position].lock);
1064+
UNLOCK_COMMAND(&alloc_lock);
1065+
/* blas_unlock(&memory[position].lock);*/
10651066
}
10661067

10671068
position ++;
@@ -1075,12 +1076,13 @@ void *blas_memory_alloc(int procpos){
10751076

10761077
do {
10771078
/* if (!memory[position].used) { */
1078-
1079-
blas_lock(&memory[position].lock);
1079+
LOCK_COMMAND(&alloc_lock);
1080+
/* blas_lock(&memory[position].lock);*/
10801081

10811082
if (!memory[position].used) goto allocation;
1082-
1083-
blas_unlock(&memory[position].lock);
1083+
1084+
UNLOCK_COMMAND(&alloc_lock);
1085+
/* blas_unlock(&memory[position].lock);*/
10841086
/* } */
10851087

10861088
position ++;
@@ -1097,7 +1099,8 @@ void *blas_memory_alloc(int procpos){
10971099

10981100
memory[position].used = 1;
10991101

1100-
blas_unlock(&memory[position].lock);
1102+
UNLOCK_COMMAND(&alloc_lock);
1103+
/* blas_unlock(&memory[position].lock);*/
11011104

11021105
if (!memory[position].addr) {
11031106
do {

0 commit comments

Comments
 (0)