I ran into this problem last year, that ordinary mutexes were not working out due to various reasons.<p>Since I do embedded programming, I looked through the ARM manuals and documentation, to see what they have on offer.<p>I ran into the lovely LDREX and STREX instructions, which are just awesome.<p>It was pretty trivial to rewrite e.g. a custom allocator that used to grab a mutex, poke its internal freelists, and release the mutex so that it instead does the poking with <i>LDREX/STREX</i>, thus obtaining thread-safety while doing the actual work it wanted to do. Lock-free programming can be beautiful like that.<p>See <a href="http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0204f/Cihbghef.html" rel="nofollow">http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc....</a> for the instruction reference on LDREX/STREX.
Oh man, now that lock free programming is such a hot topic I am dreading the code about to be written by people "teaching themselves" about it!<p>"This algorithm is much faster now that I've used some lock free programming techniques I just read about!!!"<p>Code that works correctly on x86 but fails intermittently on another processor. It's like a nightmare unfolding...
I always found this paper to be quite a good introduction to lock-free techniques:<p><a href="http://www.grame.fr/ressources/publications/LockFree.pdf" rel="nofollow">http://www.grame.fr/ressources/publications/LockFree.pdf</a><p>In the music world, such issues have been solved repeatedly over the years - seems like a little cross-polination would be a good thing ..
Raymond Chen has a pretty practical guide to lock-free algorithms on his blog.<p><a href="http://social.msdn.microsoft.com/Search/en-US?query=Lock-free%20algorithms&beta=0&rn=The+Old+New+Thing&rq=site:blogs.msdn.com/b/oldnewthing/&ac=5" rel="nofollow">http://social.msdn.microsoft.com/Search/en-US?query=Lock-fre...</a>
Does side-effect-free programming with persistent data-structures on share-nothing, actor-based architecture, in other words Erlang is qualified to be lock-free?<p>It seems that Haskell also doesn't exist.)