From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 10943 invoked by alias); 12 Dec 2010 19:59:34 -0000 Received: (qmail 10935 invoked by uid 22791); 12 Dec 2010 19:59:33 -0000 X-SWARE-Spam-Status: No, hits=-2.8 required=5.0 tests=ALL_TRUSTED,AWL,BAYES_00 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; Sun, 12 Dec 2010 19:59:29 +0000 From: "frtsang at hotmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug libstdc++/46914] New: std::atomic::exchange(...) doesn't store correct value. 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: frtsang at hotmail 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: Sun, 12 Dec 2010 19:59: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-12/txt/msg01313.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46914 Summary: std::atomic::exchange(...) doesn't store correct value. Product: gcc Version: 4.4.3 Status: UNCONFIRMED Severity: normal Priority: P3 Component: libstdc++ AssignedTo: unassigned@gcc.gnu.org ReportedBy: frtsang@hotmail.com Run the following to compile the program below. $ g++ -std=c++0x ./test.cpp -o test.tsk //test.cpp #include #include int main(int argc, char **argv) { int *a = new int(10); std::cout << "a = " << a << " *a = " << *a << std::endl; std::atomic x(a); int *ptr = x; std::cout << "ptr = " << ptr << " *ptr " << *ptr << std::endl; int *b = new int(11); std::cout << "b = " << b << " *b = " << *b << std::endl; std::cout << "x.exchange(b) = " << x.exchange(b) << std::endl; ptr = x; std::cout << "ptr = " << ptr << " *ptr " << *ptr << std::endl; int *c = new int(12); std::cout << "c = " << c << " *c = " << *c << std::endl; std::cout << "x.exchange(c) = " << x.exchange(c) << std::endl; ptr = x; std::cout << "ptr = " << ptr << " *ptr " << *ptr << std::endl; return 0; } $ g++ --version g++ (Ubuntu 4.4.3-4ubuntu5) 4.4.3 Copyright (C) 2009 Free Software Foundation, Inc. This is free software; see the source for copying conditions. There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. It runs and gives the following result. ./test.tsk a = 0x9b9c008 *a = 10 ptr = 0x9b9c008 *ptr 10 b = 0x9b9c018 *b = 11 x.exchange(b) = 0x9b9c008 ptr = 0x1ec71b *ptr -388381823 c = 0x9b9c028 *c = 12 x.exchange(c) = 0x1ec71b ptr = 0x1ec71b *ptr -388381823 After "x" is initialized with "a", it doesn't store the new value correctly in its "exchange" member function.