Skip to content

Commit 298d53c

Browse files
fix data races in blas_server and level3_thread
1 parent f986fd3 commit 298d53c

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

driver/level3/level3_thread.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,11 @@
9898
#endif
9999

100100
typedef struct {
101+
#ifdef HAVE_C11
102+
_Atomic
103+
#else
101104
volatile
105+
#endif
102106
BLASLONG working[MAX_CPU_NUMBER][CACHE_LINE_SIZE * DIVIDE_RATE_MAX];
103107
} job_t;
104108

driver/others/blas_server.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -631,7 +631,13 @@ int blas_thread_init(void){
631631
exec_blas ... returns after jobs are finished.
632632
*/
633633

634+
#if defined(USE_PTHREAD_LOCK)
635+
static pthread_mutex_t exec_queue_lock = PTHREAD_MUTEX_INITIALIZER;
636+
#elif defined(USE_PTHREAD_SPINLOCK)
637+
static pthread_spinlock_t exec_queue_lock = 0;
638+
#else
634639
static BLASULONG exec_queue_lock = 0;
640+
#endif
635641

636642
int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
637643

@@ -652,7 +658,7 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
652658
fprintf(STDERR, "Exec_blas_async is called. Position = %d\n", pos);
653659
#endif
654660

655-
blas_lock(&exec_queue_lock);
661+
LOCK_COMMAND(&exec_queue_lock);
656662

657663
while (queue) {
658664
queue -> position = pos;
@@ -717,7 +723,7 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
717723

718724
}
719725

720-
blas_unlock(&exec_queue_lock);
726+
UNLOCK_COMMAND(&exec_queue_lock);
721727

722728
#ifdef SMP_DEBUG
723729
fprintf(STDERR, "Done(Number of threads = %2ld).\n", exec_count);

0 commit comments

Comments
 (0)