1)以下是自然对齐指针的声明:
1) Is the following declaration of a naturally aligned pointer:
alignas(sizeof(void *)) volatile void * p;相当于
std::atomic<void *>在C ++ 11中?
2)更准确地说,假设这种类型的指针将以与C ++ 11中的std :: atomic相同的方式工作是否正确?
2) Saying more exactly, is it correct to assume that this type of pointer will work in the same way as std::atomic in C++11?
推荐答案不,volatile不保证该位置将被原子地读写,只是编译器无法优化多个读写。
No, volatile does not guarantee that the location will be written or read atomically, just the the compiler can't optimise out multiple reads and writes.
在某些体系结构上,如果对齐正确,处理器将自动进行读写操作,但这不是通用的,甚至不能通过一系列处理器来保证。在可能的情况下,原子的内部实现将利用体系结构功能和原子指令修饰符,因此,如果您是指原子,为什么 不 使用原子?
On certain architectures, the processor will atomically read or write if aligned correctly, but that is not universal or even guaranteed through a family of processors. Where it can, the internal implementation of atomic will take advantage of architectural features and atomic instruction modifiers, so why not use atomic, if you mean atomic?
更多推荐
自然对齐+ volatile = C ++ 11中的原子?
发布评论