Commit 2df05448 authored by Peter Trommler's avatar Peter Trommler 🥁 Committed by Ben Gamari
Browse files

RTS: Add missing memory barrier

In the work stealing queue a load-load-barrier is required to ensure
that a read of queue data cannot be reordered before a read of the
bottom pointer into the queue.

The added load-load-barrier ensures that the ordering of writes enforced
at the end of `pushWSDeque` is also respected in the order of reads in
`stealWSDeque_`. In other words, when reading `q->bottom` we want to make
sure that we see the updates to `q->elements`.

Fixes #13633

(cherry picked from commit 5c084e04)
parent 61e13e06
......@@ -194,14 +194,17 @@ stealWSDeque_ (WSDeque *q)
// concurrent popWSQueue() operation.
if ((long)b - (long)t <= 0 ) {
return NULL; /* already looks empty, abort */
}
}
// NB. the load of q->bottom must be ordered before the load of
// q->elements[t & q-> moduloSize]. See comment "KG:..." below
// and Ticket #13633.
load_load_barrier();
/* now access array, see pushBottom() */
stolen = q->elements[t & q->moduloSize];
/* now decide whether we have won */
if ( !(CASTOP(&(q->top),t,t+1)) ) {
/* lost the race, someon else has changed top in the meantime */
/* lost the race, someone else has changed top in the meantime */
return NULL;
} /* else: OK, top has been incremented by the cas call */
......
......@@ -50,14 +50,17 @@ myStealWSDeque_ (WSDeque *q, uint32_t n)
// concurrent popWSQueue() operation.
if ((long)b - (long)t <= 0 ) {
return NULL; /* already looks empty, abort */
}
}
// NB. the load of q->bottom must be ordered before the load of
// q->elements[t & q-> moduloSize]. See comment "KG:..." below
// and Ticket #13633.
load_load_barrier();
/* now access array, see pushBottom() */
stolen = q->elements[t & q->moduloSize];
/* now decide whether we have won */
if ( !(CASTOP(&(q->top),t,t+1)) ) {
/* lost the race, someon else has changed top in the meantime */
/* lost the race, someone else has changed top in the meantime */
return NULL;
} /* else: OK, top has been incremented by the cas call */
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment