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

            Bug ID: 60178
           Summary: std::mutex::try_lock failing
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: meme02 at eaku dot net

Created attachment 32124
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=32124&action=edit
Output from g++ -save-temps command above.

Problem summary:

The very simple standard example code for std::mutex usage here:

http://en.cppreference.com/w/cpp/thread/shared_mutex/unlock

-------------------
#include <iostream>
#include <mutex>

int main()
{
    std::mutex test;
    if (test.try_lock()) {
        std::cout << "first try_lock successful\n";
    } else {
        std::cout << "first try_lock NOT successful\n";
        return 0;
    }

    test.unlock();
    test.lock();

    if (test.try_lock()) {
        std::cout << "second try_lock successful\n";
    } else {
        std::cout << "second try_lock NOT successful\n";
    }

    test.lock();  // trying to lock an already-locked std::mutex will
                  // block program execution, so we'll hang here
}
-------------------

... does not perform as it should. On my system:

-------------------
[bash]$ rm -f test; /usr/local/bin/g++ -save-temps -Wall -Wextra -std=c++0x
test.cpp -o test; ./test
first try_lock successful
second try_lock successful
[bash]$ 
-------------------

Obviously, the second try_lock should fail and the program should then hang,
but this does not occur.

I'm running the latest gcc stable tarball, 4.82, updated today, no flags given
at build time. I was previously using 4.62 and the problem was there too (I
upgraded to see if that would fix it). /proc/version says "Linux version
2.6.18-194.el5PAE (mockbu...@x86-007.build.bos.redhat.com) (gcc version 4.1.2
20080704 (Red Hat 4.1.2-48)) #1 SMP Tue Mar 16 22:00:21 EDT 2010".

Reply via email to