Lingxi-Li/lock_free

Flawed memory order specification in queue

Lingxi-Li opened this issue · 0 comments

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.

  1. Initially, head == tail.
  2. 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 on head.
  3. Any later popping thread needs to hold head before doing anything else. Let hold_ptr() issue an acquire on head. Since it reads the latest value of head, it's therefore guaranteed to acquire the release issued in 2, and sees a tail which is not so outdated that breaks any invariant.