简体   繁体   English

C ++ 0x原子模板实现

[英]C++0x atomic template implementation

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

You can find discussions about this feature implementation in boost there : http://lists.boost.org/Archives/boost/2008/11/144803.php 您可以在那里找到有关此功能实现的讨论: http//lists.boost.org/Archives/boost/2008/11/144803.php

> Can the N2427 - C++ Atomic Types and Operations be implemented >可以实现N2427 - C ++原子类型和操作

> without the help of the compiler? >没有编译器的帮助?

No. 没有。

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++ (eg just plain assignment for load or store). 您甚至可以使用简单的C ++(例如,仅用于加载或存储的简单分配)。 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. MSVC提供_ReadWriteBarrier()以提供编译器排序。 Other compilers need other flags. 其他编译器需要其他标志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM