Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If your goal is production code, simply don't do that; use locks. </p> <p>In <a href="https://stackoverflow.com/questions/6089029/lock-free-queue">your previous question</a>, you have got enough information explaining why. Correct lock-free implementations of even simple data structures such as queue and stack in the absence of garbage collector are tricky and sophisticated due to <a href="http://en.wikipedia.org/wiki/ABA_problem" rel="nofollow noreferrer">the (in)famous ABA problem</a>. Unfortunately some research papers do not take ABA into account for whatever reasons; your pseudo-code seems taken from one of such papers. If you translate it to C and use heap allocated memory for nodes, it will cause undeterministic bugs if used in real code.</p> <p>If you are doing this stuff to gain experience, then don't expect SO fellows to solve it for you. You have to read all the cited materials and much more, make sure you really understand all nuances of lock-free algorithms such as ABA, study various techniques intended to address the issue, study existing lock-free implementations, etc.</p> <p>Finally, little guidance for translating the given pseudo-code into C:</p> <p><code>q^.value ← x</code> means <code>q_elem-&gt;data = x;</code><br> <code>repeat ... until COMPARE&amp;SWAP(head, p, p^.next)</code> is equivalent to <code>do {...} while (!__sync_bool_compare_and_swap(q_obj-&gt;head, q_elem, q_elem-&gt;next);</code> </p> <p>where <code>q_obj</code> is an instance of type <code>queue_t</code> (i.e. a queue) and <code>q_elem</code> is an instance of type <code>queueelem_t</code> (i.e. a queue node).</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.
    2. VO
      singulars
      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