自然对齐+ volatile = C ++ 11中的原子?

编程入门 行业动态 更新时间:2024-10-26 23:32:13
本文介绍了自然对齐+ volatile = C ++ 11中的原子?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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中的原子?

本文发布于:2023-11-12 16:54:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1582024.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:原子   自然   volatile

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!