public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug libstdc++/46914] New: std::atomic<int*>::exchange(...) doesn't store correct value.
@ 2010-12-12 19:59 frtsang at hotmail dot com
  2010-12-12 20:15 ` [Bug libstdc++/46914] " frtsang at hotmail dot com
                   ` (17 more replies)
  0 siblings, 18 replies; 19+ messages in thread
From: frtsang at hotmail dot com @ 2010-12-12 19:59 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: std::atomic<int*>::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 <iostream>
#include <stdatomic.h>

int main(int argc, char **argv)
{
    int *a = new int(10);
    std::cout << "a = " << a << " *a = " << *a << std::endl;

    std::atomic<int*> 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.


^ permalink raw reply	[flat|nested] 19+ messages in thread

end of thread, other threads:[~2011-02-02 18:33 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-12-12 19:59 [Bug libstdc++/46914] New: std::atomic<int*>::exchange(...) doesn't store correct value frtsang at hotmail dot com
2010-12-12 20:15 ` [Bug libstdc++/46914] " frtsang at hotmail dot com
2010-12-12 20:51 ` paolo.carlini at oracle dot com
2011-01-27 14:48 ` paolo.carlini at oracle dot com
2011-01-27 14:57 ` redi at gcc dot gnu.org
2011-01-27 15:17 ` paolo.carlini at oracle dot com
2011-01-27 15:18 ` redi at gcc dot gnu.org
2011-01-27 15:52 ` paolo.carlini at oracle dot com
2011-01-27 15:57 ` paolo.carlini at oracle dot com
2011-01-27 16:11 ` paolo.carlini at oracle dot com
2011-01-28  8:48 ` frtsang at hotmail dot com
2011-01-28 10:11 ` paolo.carlini at oracle dot com
2011-01-28 10:56 ` paolo.carlini at oracle dot com
2011-02-01 17:30 ` paolo.carlini at oracle dot com
2011-02-01 17:39 ` paolo.carlini at oracle dot com
2011-02-01 19:40 ` paolo at gcc dot gnu.org
2011-02-01 19:42 ` paolo at gcc dot gnu.org
2011-02-01 19:43 ` paolo.carlini at oracle dot com
2011-02-02 18:33 ` dnovillo at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).