Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Force use of locks inside std::atomic during debugging with libstdc++

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.

like image 711
goji Avatar asked Nov 02 '22 13:11

goji


1 Answers

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.

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

PS. Actually, you may compile with -m32 -march=i386 and provide yourself the required external functions.

like image 199
chill Avatar answered Nov 04 '22 07:11

chill