[Bug libstdc++/46294] New: Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
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/

[Bug libstdc++/46294] Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

--- Comment #1 from Dan Weber  2010-11-03 18:11:11 
UTC ---
Created attachment 22260
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22260
Spinlock Test g++ ii output


[Bug libstdc++/46294] Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

--- Comment #2 from Dan Weber  2010-11-03 18:11:37 
UTC ---
Created attachment 22261
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22261
G++ Assembler Output atomic test


[Bug libstdc++/46294] Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

--- Comment #3 from Dan Weber  2010-11-03 18:12:01 
UTC ---
Created attachment 22262
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22262
Spinlock Test G++ object file


[Bug libstdc++/46294] Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

--- Comment #4 from Dan Weber  2010-11-03 18:12:58 
UTC ---
Created attachment 22263
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22263
TBB based spinlock (working)

Compiler with -ltbb keep -fopenmp, but -std=c++0x is unnecessary


[Bug libstdc++/46294] Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

--- Comment #5 from Dan Weber  2010-11-03 18:16:28 
UTC ---
Probably requires testing using a machine that has multiple cores :)

My Machine is an INtel i7 720qm, so it has 4 cores + 4 hyperthreads fyi.


[Bug libstdc++/46294] Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

--- Comment #6 from Dan Weber  2010-11-03 18:19:04 
UTC ---
Created attachment 22264
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=22264
TBB Spinlock assembler (includes compare and swap and fetch and store ops
inline)


[Bug libstdc++/46294] Spinlock with atomic primitives fails

2010-11-03 Thread dan at blinkmind dot com
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46294

Dan Weber  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
 Resolution||INVALID

--- Comment #7 from Dan Weber  2010-11-03 18:24:51 
UTC ---
didn't realize that compare_exchange was updating the reference value... after
making adjustments for that this was fixed.