5

I've done a bit of a google and can't seem to turn up a GCC option or libstdc++ macro for this. Is it possible to force the use of locking internally on all the std::atomic template specializations. On some platforms some of the specializations are locking anyway, so it certainly seems like a feasible option.

In the past I've found the use of std::atomic to be very painful when debugging data-races with tools such as Valgrind (Helgrind or DRD) due to the enormous number of false positives. If use of atomics is pervasive enough, suppression files seem to not be a very scalable solution.

4

1 回答 1

2

没有办法,AFAIK。GCC 通过无锁内置函数(、、等)实现 C++11__atomic_fetch_add原子__atomic_test_and_set。根据机器定义中可用的内容,GCC 可能会发出一些有效的 insn 序列,或者作为最后的手段,使用比较和交换循环。如果没有任何有用的东西可用,GCC 只会发出对具有相同名称和参数的外部函数的调用。

http://gcc.gnu.org/onlinedocs/gcc-4.8.1/gcc/_005f_005fatomic-Builtins.html#_005f_005fatomic-Builtins

PS。实际上,您可以编译-m32 -march=i386并为自己提供所需的外部函数。

于 2013-10-02T22:48:15.077 回答