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.