Flawed memory order specification in queue
Lingxi-Li opened this issue · 0 comments
Lingxi-Li commented
With current memory order specification, no happens-before requirement is imposed between head
and tail
update. Consider try_pop()
. hold_ptr()
ensures that the latest value of head
is read, yet any value in the modification order of tail
can be read. Therefore, head != tail
doesn't necessarily mean a non-empty queue.
Let's try to establish order between head
and tail
.
- Initially,
head == tail
. - The first thread that successfully pops is OK. It sees a
tail
which is not so outdated that breaks any invariant. The pop should issue a release onhead
. - Any later popping thread needs to hold
head
before doing anything else. Lethold_ptr()
issue an acquire onhead
. Since it reads the latest value ofhead
, it's therefore guaranteed to acquire the release issued in 2, and sees atail
which is not so outdated that breaks any invariant.