Skip to content

Commit 39eb43d

Browse files
authored
Improve thread safety of pthreads builds that rely on C11 atomic operations for locking (#5170)
* Tighten memory orders for C11 atomic operations
1 parent 1d5ed5c commit 39eb43d

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

driver/others/blas_server.c

+4-2
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,8 @@ typedef struct {
146146
} thread_status_t;
147147

148148
#ifdef HAVE_C11
149-
#define atomic_load_queue(p) __atomic_load_n(p, __ATOMIC_RELAXED)
150-
#define atomic_store_queue(p, v) __atomic_store_n(p, v, __ATOMIC_RELAXED)
149+
#define atomic_load_queue(p) __atomic_load_n(p, __ATOMIC_ACQUIRE)
150+
#define atomic_store_queue(p, v) __atomic_store_n(p, v, __ATOMIC_RELEASE)
151151
#else
152152
#define atomic_load_queue(p) (blas_queue_t*)(*(volatile blas_queue_t**)(p))
153153
#define atomic_store_queue(p, v) (*(volatile blas_queue_t* volatile*)(p) = (v))
@@ -637,7 +637,9 @@ int exec_blas_async(BLASLONG pos, blas_queue_t *queue){
637637

638638
#ifdef SMP_SERVER
639639
// Handle lazy re-init of the thread-pool after a POSIX fork
640+
LOCK_COMMAND(&server_lock);
640641
if (unlikely(blas_server_avail == 0)) blas_thread_init();
642+
UNLOCK_COMMAND(&server_lock);
641643
#endif
642644
BLASLONG i = 0;
643645
blas_queue_t *current = queue;

0 commit comments

Comments
 (0)