http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

           Summary: Spinlock with atomic primitives fails
           Product: gcc
           Version: 4.5.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: d...@blinkmind.com


Created attachment 22259
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22259
Spinlock Test g++ application code

Trying to use std::atomic as a spinlock with
compare_exchange_weak/compare_exchange_strong fails.

It results in multiple assertion failures and multiple reads of memory that are
inaccurate leading to race conditions and problems in executing code.

To verify that this should work properly, I also tested with tbb's atomic (also
provided) which works just fine.









d...@brighty:~/workspace/blinkmind/applications/fast-queues/test$ g++-4.5 -v -o
spinlocktest -fopenmp -std=c++0x spinlocktest.cpp -save-temps
Using built-in specs.
COLLECT_GCC=g++-4.5
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.5.1/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro
4.5.1-9ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.5/README.Bugs
--enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.5 --enable-shared --enable-multiarch
--enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib
--without-included-gettext --enable-threads=posix
--with-gxx-include-dir=/usr/include/c++/4.5 --libdir=/usr/lib --enable-nls
--with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug
--enable-libstdcxx-time=yes --enable-plugin --enable-gold
--with-plugin-ld=ld.gold --enable-objc-gc --disable-werror --with-arch-32=i686
--with-tune=generic --enable-checking=release --build=x86_64-linux-gnu
--host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.5.1 (Ubuntu/Linaro 4.5.1-9ubuntu1) 
COLLECT_GCC_OPTIONS='-v' '-o' 'spinlocktest' '-fopenmp' '-std=c++0x'
'-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/4.5.1/cc1plus -E -quiet -v -D_GNU_SOURCE
-D_REENTRANT spinlocktest.cpp -D_FORTIFY_SOURCE=2 -mtune=generic -march=x86-64
-std=c++0x -fopenmp -fpch-preprocess -fstack-protector -o spinlocktest.ii
ignoring nonexistent directory "/usr/local/include/x86_64-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../../../x86_64-linux-gnu/include"
ignoring nonexistent directory "/usr/include/x86_64-linux-gnu"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.5
 /usr/include/c++/4.5/x86_64-linux-gnu
 /usr/include/c++/4.5/backward
 /usr/local/include
 /usr/lib/gcc/x86_64-linux-gnu/4.5.1/include
 /usr/lib/gcc/x86_64-linux-gnu/4.5.1/include-fixed
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-o' 'spinlocktest' '-fopenmp' '-std=c++0x'
'-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/4.5.1/cc1plus -fpreprocessed spinlocktest.ii
-quiet -dumpbase spinlocktest.cpp -mtune=generic -march=x86-64 -auxbase
spinlocktest -std=c++0x -version -fopenmp -fstack-protector -o spinlocktest.s
GNU C++ (Ubuntu/Linaro 4.5.1-9ubuntu1) version 4.5.1 (x86_64-linux-gnu)
    compiled by GNU C version 4.5.1, GMP version 4.3.2, MPFR version 3.0.0-p3,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Ubuntu/Linaro 4.5.1-9ubuntu1) version 4.5.1 (x86_64-linux-gnu)
    compiled by GNU C version 4.5.1, GMP version 4.3.2, MPFR version 3.0.0-p3,
MPC version 0.8.2
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: ee038d8a671383b128b393ee39ab4227
COLLECT_GCC_OPTIONS='-v' '-o' 'spinlocktest' '-fopenmp' '-std=c++0x'
'-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
 as -V -Qy --64 -o spinlocktest.o spinlocktest.s
GNU assembler version 2.20.51 (x86_64-linux-gnu) using BFD version (GNU
Binutils for Ubuntu) 2.20.51-system.20100908
COMPILER_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.5.1/:/usr/lib/gcc/x86_64-linux-gnu/4.5.1/:/usr/lib/gcc/x86_64-linux-gnu/:/usr/lib/gcc/x86_64-linux-gnu/4.5.1/:/usr/lib/gcc/x86_64-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/x86_64-linux-gnu/4.5.1/:/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../../../lib64/:/lib/../lib64/:/usr/lib/../lib64/:/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../../:/lib/:/usr/lib/:/usr/lib/x86_64-linux-gnu/
Reading specs from /usr/lib/gcc/x86_64-linux-gnu/4.5.1/libgomp.spec
COLLECT_GCC_OPTIONS='-v' '-o' 'spinlocktest' '-fopenmp' '-std=c++0x'
'-save-temps' '-shared-libgcc' '-mtune=generic' '-march=x86-64' '-pthread'
 /usr/lib/gcc/x86_64-linux-gnu/4.5.1/collect2 --build-id --no-add-needed
--eh-frame-hdr -m elf_x86_64 --hash-style=gnu -dynamic-linker
/lib64/ld-linux-x86-64.so.2 -z relro -o spinlocktest
/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../../../lib64/crt1.o
/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../../../lib64/crti.o
/usr/lib/gcc/x86_64-linux-gnu/4.5.1/crtbegin.o
-L/usr/lib/gcc/x86_64-linux-gnu/4.5.1
-L/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../../../lib64 -L/lib/../lib64
-L/usr/lib/../lib64 -L/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../..
-L/usr/lib/x86_64-linux-gnu spinlocktest.o -lstdc++ -lm -lgomp -lgcc_s -lgcc
-lpthread -lc -lgcc_s -lgcc /usr/lib/gcc/x86_64-linux-gnu/4.5.1/crtend.o
/usr/lib/gcc/x86_64-linux-gnu/4.5.1/../../../../lib64/crtn.o

Reply via email to