[cpp-threads] Alternative to dependent load

Joseph Seigh jseigh_cp00 at xemaps.com
Wed Oct 6 01:08:18 BST 2010


  Lock-free programming usually makes heavy use of dependent loads as an alternative to load w/ acquire.  For platforms without dependent load, Paul McKenney came up with a technique that delays storing of a pointer to an object that has just been initialized until after all processors have executed an acquire memory barrier or the equivalent.  The technique is basically RCU with the memory barriers as quiesce points and with some inter processor signaling to speed things up.

It might be useful to move RCU wait from the write phase, where it slows things down, to the heap phase.   Just keep freed memory on the heap and don't reallocate it until all other processors no longer have any references to it.  Then when you allocate memory for an object, you can initialize it and without delay, subsequently globally publish it without requiring other processors to do a load w/ acquire to properly see the initial state of the object.

There some caveats.  You'd have to be careful with architectures that allow speculative reads.  You probably couldn't allow in use memory to share cache lines with unallocated heap memory.

Systems like Java that have GC get most of this for free by the nature of GC.  You wouldn't have to do too much more to make it work.   I've seen some interest there for the ability to create immutable objects and publish them without having to use volatile.

Joseph Seigh





More information about the cpp-threads mailing list