title: Atomic Compare And Swap with struct in Go
body: <p>I am trying to create a non-blocking queue package for concurrent application using the algorithm by Maged M. Michael and Michael L. Scott as described <a href="http://www.cs.rochester.edu/research/synchronization/pseudocode/queues.html#nbq" rel="noreferrer">here</a>.</p>
  
  <p>This requires the use of atomic CompareAndSwap which is offered by the <code>"sync/atomic"</code> package.<br>
  I am however not sure what the Go-equivalent to the following pseudocode would be:</p>
  
  <pre><code>E9:   if CAS(&amp;tail.ptr-&gt;next, next, &lt;node, next.count+1&gt;)
  </code></pre>
  
  <p>where <code>tail</code> and <code>next</code> is of type:</p>
  
  <pre><code>type pointer_t struct {
      ptr   *node_t
      count uint
  }
  </code></pre>
  
  <p>and <code>node</code> is of type:</p>
  
  <pre><code>type node_t struct {
      value interface{}
      next  pointer_t
  }
  </code></pre>
  
  <p>If I understood it correctly, it seems that I need to do a CAS with a struct (both a pointer and a <code>uint</code>). Is this even possible with the <code>atomic</code>-package?</p>
  
  <p>Thanks for help!</p>