Skip to content

Commit 13db0dc

Browse files
vtjnashJeffBezanson
authored andcommitted
partr: fix rare segfault (#32530)
The write to 'prio' might be arbitrarily delayed, after some other thread has already popped the task. This commit ensures that all writes to that field are always behind the same lock as the modification to the queue itself. fix #32520
1 parent f18808d commit 13db0dc

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

src/partr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,10 +123,10 @@ static inline int multiq_insert(jl_task_t *task, int16_t priority)
123123

124124
heaps[rn].tasks[heaps[rn].ntasks++] = task;
125125
sift_up(&heaps[rn], heaps[rn].ntasks-1);
126-
jl_mutex_unlock_nogc(&heaps[rn].lock);
127126
int16_t prio = jl_atomic_load(&heaps[rn].prio);
128127
if (task->prio < prio)
129-
jl_atomic_compare_exchange(&heaps[rn].prio, prio, task->prio);
128+
jl_atomic_store(&heaps[rn].prio, task->prio);
129+
jl_mutex_unlock_nogc(&heaps[rn].lock);
130130

131131
return 0;
132132
}

0 commit comments

Comments
 (0)