Electronics with passion: amplifiers and power supplies, FET's and vacuum tubes..
programming

Interlocked exchange on Linux: undefined reference to `__sync_add_and_fetch_4′

I am pretty conservative in selecting the tools I use for my projects, thus sticking with good old C++. To be really productive on C++ - using of some sort of smart pointers is a must. And to make things a bit more complicated there are multi-core machines, that run different OS'es and the project has to build correctly for 32 and 64 bits. Here we got things to protect...Using atomic barriers in GCC (supported since v.4.1.0 or so) may allow significant performance gain in comparison to pthread' mutexes. Though I've not done any benchmarks of this matter on Linux (yet), the gain on Windows while migrating from critical sections to interlocked exchange was pretty significant.The GCC built-in functions for atomic memory access work wonders: http://gcc.gnu.org/onlinedocs/gcc-4.1.2/gcc/Atomic-Builtins.htmlThe only problem - it did not compile on 32 bit Linux, throwing the following linker error at me:

undefined reference to `__sync_add_and_fetch_4'

Defining the compiler's option:

-march=pentium

solved the issue (i486 worked here Ok too).

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.