use*_*177 4 c++ pointers atomic
该代码在i7-4790处理器(x86-64)上的VC++ 2013(v120)下编译没有问题.
int main()
{
std::atomic<std::unique_ptr<int>> p;
p.store(std::make_unique<int>(5));
}
Run Code Online (Sandbox Code Playgroud)
一旦main()返回,我就崩溃了:
表达式:_BLOCK_TYPE_IS_VALID(pHead-> nBlockUse)
这是怎么回事?
Nat*_*ica 12
你无法std::atomic用a 实例化a std::unique_ptr. cppreference
std :: atomic可以用任何TriviallyCopyable类型实例化.std :: atomic既不可复制也不可移动.
并且a std::unique_ptr不是TriviallyCopyable
该类满足MoveConstructible和MoveAssignable的要求,但不满足CopyConstructible或CopyAssignable的要求.
您可以使用std::shared_ptr已定义的自由函数,以允许您拥有原子存储和加载