Work around missing atomic ops on shared_ptr.

The c++ library that comes with gcc 4.8 (20130203) does not implement
atomic_* operations on shared_ptr.  The work-around is to test if a
library implements this and if not, to work around it using a couple
of global spinlocks.
Once support is implemented, the library should atomatically detect
this on rebuild (but be sure to rebuild all code depending on it).