If you heap allocate an object with shared_ptr
on thread A , then copy the shared_ptr
to another thread without any synchronization. Is the other thread guaranteed to see a fully constructed object?
int main(){
auto sp = std::make_shared<int>(5);
auto f=std::async(std::launch::async, [sp](){
std::cout<<*sp;});
}
Is it guaranteed to print 5?