From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 1216 invoked by alias); 3 Nov 2010 18:10:57 -0000 Received: (qmail 1201 invoked by uid 22791); 3 Nov 2010 18:10:55 -0000 X-SWARE-Spam-Status: No, hits=-1.0 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00,TBC,TW_BJ,TW_CX,TW_DC,TW_GX,TW_LG X-Spam-Check-By: sourceware.org Received: from localhost (HELO gcc.gnu.org) (127.0.0.1) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 03 Nov 2010 18:10:50 +0000 From: "dan at blinkmind dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/46294] New: Spinlock with atomic primitives fails X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: libstdc++ X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: dan at blinkmind dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Date: Wed, 03 Nov 2010 18:10:00 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2010-11/txt/msg00401.txt.bz2 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: unassigned@gcc.gnu.org ReportedBy: dan@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. dan@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