Skip to content

Commit

Permalink
Merge pull request #1299 from martin-frbg/race_fixes
Browse files Browse the repository at this point in the history
Fix thread data races uncovered by gcc thread sanitizer
  • Loading branch information
martin-frbg authored Sep 9, 2017
2 parents 00740c0 + ba1f91f commit f66d908
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 14 deletions.
14 changes: 8 additions & 6 deletions driver/others/blas_server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
19 changes: 11 additions & 8 deletions driver/others/memory.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ++;
Expand All @@ -1075,12 +1076,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 ++;
Expand All @@ -1097,7 +1099,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 {
Expand Down

0 comments on commit f66d908

Please sign in to comment.