Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was stuck on this same question, and sceptical that this could be an optimization, so I asked Maged Michael, one of the authors of this paper. This is his response:</p> <blockquote> <p>E7 and D5 are needed for correctness.</p> <p>The following case shows why E7 is needed:</p> <ul> <li><p>Thread P reads the value <code>&lt;A,num1&gt;</code> from Q->Tail in line E5</p></li> <li><p>Other threads change the queue such that the node A is removed and maybe later reused in a different queue (or a different structure with similar node structure) or allocated by a thread to insert it in this same queue. In any case A is not in this queue and its next field has the value <code>&lt;NULL, num2&gt;</code>.</p></li> <li><p>In line E6, P reads the value <code>&lt;NULL, num2&gt;</code> from A->next into next.</p></li> <li><p>(Skipping line E7)</p></li> <li><p>In line E8, P finds next.ptr == NULL</p></li> <li><p>In line E9, P executes a successful CAS on A->next as it finds <code>A-&gt;next == &lt;NULL, num2&gt;</code> and sets it to <code>&lt;node,num2+1&gt;</code>.</p></li> <li><p>Now, the new node is incorrectly inserted after A which doesn't belong to this queue. This might also corrupt another unrelated structure.</p></li> </ul> <p>With line E7, P would have discovered that Q->Tail has changed and would have started over.</p> <p>Similarly for D5.</p> </blockquote> <p>Basically, <em>if</em> our read from <code>tail.ptr-&gt;next</code> is going to make us believe that the next pointer is null (and thus that we may write to the node), we must double check that this null refers to the end of the <em>current</em> queue. If the node is still in the queue after we read the null, we may assume that it really was the end of queue, and the compare-and-swap will (given the counter) catch the case where anything happened to this node <em>after</em> the test in <code>E7</code> (removing the node from the queue will necessarily involve mutating its next pointer).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload