C ++ 0x原子模板实现 [英] C++0x atomic template implementation

查看:98
本文介绍了C ++ 0x原子模板实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道类似的模板退出在英特尔的TBB,除了我找不到任何实现在谷歌或Boost库。

I know that similar template exits in Intel's TBB, besides that I can't find any implementation on google or in Boost library.

推荐答案

您可以在此处找到有关此功能实施的讨论: http:// lists。 boost.org/Archives/boost/2008/11/144803.php

You can find discussions about this feature implementation in boost there : http://lists.boost.org/Archives/boost/2008/11/144803.php


> N2427 - C ++原子类型和在没有编译器的帮助下,执行操作

> Can the N2427 - C++ Atomic Types and Operations be implemented

>

否。

如果你可以编写内联汇编程序(或者
的单独编译的汇编程序很重要),它们不需要是内在函数,那么你可以写
直接操作自己。你
甚至可以使用简单的C ++
(例如,只是对于加载
或存储的赋值)。您需要
编译器支持的原因是阻止
不适当的优化:原子
操作无法优化出来,
一般不能重新排序
之前或之后其他操作。
这意味着在原子
存储必须完成之前执行甚至非原子的
存储,并且不能将
缓存在寄存器中(例如)。
此外,在原子操作之前不能提升
原子操作之后发生的加载
。在一些
编译器上,只使用内联汇编程序
就足够了。在其他方面,调用
外部函数就足够了。 MSVC
提供
_ReadWriteBarrier()来提供编译器排序。其他编译器
需要其他标志。

They don't need to be intrinsics if you can write inline assembler (or separately-compiled assembler for that matter) then you can write the operations themselves directly. You might even be able to use simple C++ (e.g. just plain assignment for load or store). The reason you need compiler support is preventing inappropriate optimizations: atomic operations can't be optimized out, and generally must not be reordered before or after any other operations. This means that even non-atomic stores performed before an atomic store have to be complete, and can't be cached in a register (for example). Also, loads that occur after an atomic operation cannot be hoisted before the atomic op. On some compilers, just using inline assembler is enough. On others, calling an external function is enough. MSVC provides _ReadWriteBarrier() to provide the compiler ordering. Other compilers need other flags.

这篇关于C ++ 0x原子模板实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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