By reading the c++11 draft n3242, section 20.7.2.5, looks like we have atomic operations on shared_ptr, which enables us do lock-free on complicated structure without worrying about GC/memory leak.
However, I couldn't use it successfully in GCC-4.7.0. I simply tested the following program
#include <atomic>
#include <memory>
#include <string>
struct X {
int x;
double y;
std::string s;
};
int main() {
std::shared_ptr<X> x(new X);
auto p = std::atomic_load(&x);
}
and it has compiler error:
c.cpp:13:33: error: no matching function for call to ‘atomic_load(std::shared_ptr<X>*)’
Does anyone know what I missed here? Or is it simply gcc hasn't implemented that yet?