https://llvm.org/bugs/show_bug.cgi?id=25500

            Bug ID: 25500
           Summary: Atomic compare_exchange_weak/strong
           Product: libc++
           Version: 3.7
          Hardware: Macintosh
                OS: MacOS X
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangb...@nondot.org
          Reporter: venkat.mu...@gmail.com
                CC: llvm-bugs@lists.llvm.org, mclow.li...@gmail.com
    Classification: Unclassified

Created attachment 15269
  --> https://llvm.org/bugs/attachment.cgi?id=15269&action=edit
A test c++ code that shows the bug. It spawns 8 threads.

The following snippet does not work as expected.

struct Node { Node* next; };

std::atomic<Node*> head (nullptr);

// Is like free
void push (void* p)
{
    Node* n = (Node*) p;
    n->next = head.load (); 
    while (!head.compare_exchange_strong (n->next, n));
}

// is like malloc
void* pop ()
{
    Node* n = head.load (); 
    while (n &&
          !head.compare_exchange_strong (n, n->next));

    return n ? n : malloc (SIZE);
}

The attached file with the driver crashes every 1 in 5 times.

clang++ -g  -std=c++11 test.cpp

-- 
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to