Look at the sample, please
std::atomic < std::shared_ptr < int > > a;
std::shared_ptr < int > b;
std::shared_ptr < int > c = std::make_shared < int > (10);
while(a.compare_exchange_weak(b, c));
assert(a.load() == c);
assert(a.load().use_count() == 2); // <- assertion is failed.
What do you think? Is it compiler error?
Build with msvs 2013 in win32 mode
Your program exhibits undefined behavior.
29.5/1 There is a generic class template
atomic<T>
. The type of the template argumentT
shall be trivially copyable (3.9).
shared_ptr<int>
is not trivially copyable.
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