<div dir="ltr"><div>There&#39;s a ticket that describes the design here:</div><div>    <a href="http://ghc.haskell.org/trac/ghc/ticket/8157#comment:1">http://ghc.haskell.org/trac/ghc/ticket/8157#comment:1</a></div><div>It is a fairly simple extension of the casMutVar# that has been in since 7.2.  The implementation is on the `atomics` branch currently.</div>

<div><br></div><div>Feel free to add your views either here or on that task&#39;s comments.  </div><div><br></div><div>One example of an alternative design would be Carter&#39;s proposal to expose something closer to the <a href="http://llvm.org/docs/Atomics.html">full LLVM concurrency ops</a>:</div>

<div><br></div><div>Schonwald <span dir="ltr">&lt;<a href="mailto:carter.schonwald@gmail.com" target="_blank">carter.schonwald@gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">

<div dir="ltr"><div>i&#39;m kinda thinking that we should do the analogue of exposing all the different memory model level choices (because its not that hard to add that), and when the person building it has an old version of GCC, it falls back to the legacy atomic operations?</div>

<div><br></div><div>This also gives a nice path to how to upgrade to the inline asm approach.</div></div></blockquote></div><div><br></div><div>These LLVM ops include many parameterized configurations of loads, stores, cmpxchg, atomicrmw and barriers.  In fact, it implements much more than is natively supported in most hardware, but it provides a uniform abstraction.</div>

<div><br></div><div><div>My original thought was that any kind of abstraction like that would be built and maintained as a Haskell library, and only the most rudimentary operations (required to get access to process features) would be exposed as primops.  Let&#39;s call this the &quot;small&quot; set of concurrent ops.</div>

</div><div><br></div><div>If we want the &quot;big set&quot; I think we&#39;re doomed to <b><i>reproduce</i></b> the logic that maps LLVM concurrency abstractions onto machine ops irrespective of whether those abstractions are implemented as Haskell functions or as primops:</div>

<div><div><ul><li>If the former, then the Haskell library must map the full set of ops to the reduced small set (just like LLVM does internally)</li><li>If we instead have a large set of LLVM-isomorphic primops.... then to support the same primops <b>in the native code backend </b>will, again, require reimplementing all configurations of all operations.</li>

</ul></div><div>Unless... we want to make concurrency ops something that require the LLVM backend?</div><div><br></div>Right now there is not a <b><i>performance</i></b> disadvantage to supporting a smaller rather than a larger set of concurrency ops (LLVM has to emulate these things anyway, or &quot;round up&quot; to more expensive ops).  The scenario where it would be good to target ALL of LLVMs interface would be if processors and LLVM improved in the future, and we automatically got the benefit of better HW support for some op on on some arch.</div>

<div><br></div><div>I&#39;m a bit skeptical of that proposition itself, however.  I personally don&#39;t really like a world where we program with &quot;virtual operations&quot; that don&#39;t really exist (and thus can&#39;t be <i>tested</i> against properly).  Absent formal verification, it seems hard to get this code right anyway.  Errors will be undetectable on existing architectures.</div>

<div><br></div><div>  -Ryan</div><div><br></div><div><br></div><div><br></div></div>