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?
There is a proposal to deprecate these atomic_store/atomic_load methods for shared_ptr in favor of the new atomic_shared_ptr class: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2014/n4162.pdf
So by the time you get a libstc++ version with atomic_load it may very well contain the new atomic pointers already, which are better in several aspects.
MSVC STL has implemented these methods a while ago, and libc++ also claims full C++11/14 compliance, so they must be available in its latest versions.
Looks like it's just not in libstdc++ yet.
It's also not in libc++
VS11 beta has it. I think this is the first thing I've found in VS11's library that wasn't in libc++.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With