C ++ int操作在mips架构上是原子的 [英] Are C++ int operations atomic on the mips architecture

查看:291
本文介绍了C ++ int操作在mips架构上是原子的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道我是否可以读取或写入共享int值,而不锁定在mips cpu(尤其是亚马逊或多瑙河)。我的意思是如果这样的读或写是原子的(其他线程不能中断他们)。要清楚 - 我不想阻止线程之间的竞争,但我关心int值本身没有损坏。

I wonder if I could read or write shared int value without locking on mips cpu (especially Amazon or Danube). What I mean is if such a read or write are atomic (other thread can't interrupt them). To be clear - I don't want to prevent the race between threads, but I care if int value itself is not corrupted.

假设编译器将所有ints cpu字的边界,应该是可能的。我使用gcc(g ++)。测试也显示它似乎工作正常。

Assuming that the compiler aligns all ints at the boundaries of cpu word, it should be possible. I use gcc (g++). Tests also shows that it seems work correctly. But maybe someone knows it for sure?

推荐答案

使用gcc的内置原子操作,如果不支持这些操作, :
http://gcc.gnu。 org / onlinedocs / gcc-4.1.2 / gcc / Atomic-Builtins.html

Use gcc's builtin atomic operations and you'll get warnings if they're not supported: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.html

看起来像加法/减法和测试的组合可能在硬件上:
http:/ /rswiki.csie.org/lxr/http/source/include/asm-mips/atomic.h

It looks like combinations of addition/subtraction and testing (at least) are possible on the hardware: http://rswiki.csie.org/lxr/http/source/include/asm-mips/atomic.h

这篇关于C ++ int操作在mips架构上是原子的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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