在使用libstdc ++调试期间强制使用std :: atomic内部的锁 [英] Force use of locks inside std::atomic during debugging with libstdc++
问题描述
我做了一些google,似乎没有打开 GCC 选项或 libstdc ++ 宏。是否可以在所有 std :: atomic
模板专用化上强制使用锁定。在某些平台上,一些专业版本正在锁定,所以它肯定似乎是一个可行的选择。
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.
在过去,我发现使用 Valgrind ( Helgrind 或 DRD )调试数据时,使用std :: atomic >)由于大量的假阳性。如果使用原子是普遍的,抑制文件似乎不是一个非常可扩展的解决方案。
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.
推荐答案
没有办法,AFAIK 。 GCC通过无锁内建函数( __ atomic_fetch_add
, __ atomic_test_and_set
等)实现C ++ 11原子。根据机器定义中可用的内容,GCC可能会发出一些有效的insn序列,或者作为最后手段,使用比较和交换循环。如果没有什么有用的可用,GCC只是发出对具有相同名称和参数的外部函数的调用。
There is no way, AFAIK. GCC implements C++11 atomics via lock-free builtin functions (__atomic_fetch_add
, __atomic_test_and_set
, etc). Depending on what is available in the machine definition, GCC may emit some efficient insn sequence or, as a last resort, use a compare-and-swap loop. If nothing useful is available, GCC just emits calls to external functions with the same names and arguments.
PS。实际上,你可以使用 -m32 -march = i386
编译并提供所需的外部函数。
PS. Actually, you may compile with -m32 -march=i386
and provide yourself the required external functions.
这篇关于在使用libstdc ++调试期间强制使用std :: atomic内部的锁的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!