被读取保证在C / C一个指令一个布尔值/写++ [英] Is read/write of a bool value guaranteed to be one instruction in C/C++

查看:160
本文介绍了被读取保证在C / C一个指令一个布尔值/写++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法想象一个体系结构将设计多个指令其最小的数据类型的访问,但也许有与流水线一些问题,我不考虑?

I can't imagine an architecture would design an access to its smallest data type in multiple instructions, but maybe there is some problem with pipelining that I am not considering?

推荐答案

无论是布尔对象读取和写入单个操作的不保证由C ++标准,因为这将使制约了底层硬件,其中C和C ++尽量减少上。

Whether a bool object is read and written in a single operation is not guaranteed by the C++ standard, because that would put constraints on the underlying hardware, which C and C++ try to minimize.

不过,请注意,在多线程情况下的问题,无论是读/写数据类型为 原子只有一个问题的一半。另一半是改变一些地址是否 反映在所有缓存(即那些地方不同的内核),以及它们是否以相同的顺序在所有线程体现。对于您将需要记忆的障碍。

However, note that in multi-threading scenarios the question whether reading/writing a data type is atomic is only one half of the problem. The other half is whether changes to some address are reflected in all caches (i.e. those local to different cores), and whether they are reflected across all threads in the same order. For that you will need memory barriers.

这篇关于被读取保证在C / C一个指令一个布尔值/写++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆