This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c++/57975] New: Core dump caused by linking with -lpthread


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

            Bug ID: 57975
           Summary: Core dump caused by linking with -lpthread
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: michi at triodia dot com

The following code works as expected when compiling with

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

The program hangs until it is interrupted.

When I compile the same code with

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

I get a segfault in wait():

Program received signal SIGSEGV, Segmentation fault.
__pthread_mutex_unlock_usercnt (mutex=0x0, decr=0) at pthread_mutex_unlock.c:37
37    pthread_mutex_unlock.c: No such file or directory.
(gdb) bt
#0  __pthread_mutex_unlock_usercnt (mutex=0x0, decr=0) at
pthread_mutex_unlock.c:37
#1  0x00007ffff7bc8c17 in pthread_cond_wait@@GLIBC_2.3.2 ()
    at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:94
#2  0x00007ffff79698ec in
std::condition_variable::wait(std::unique_lock<std::mutex>&) ()
   from /usr/lib/x86_64-linux-gnu/libstdc++.so.6
#3  0x0000000000400a69 in main () at test.cpp:13

Here is the complete source:

#include <condition_variable>
#include <mutex>

int main(int, char**)
{
    bool predicate = false;
    std::mutex mutex;
    std::condition_variable condvar;

    std::unique_lock<decltype(mutex)> lock;
    while (!predicate)
    {
        condvar.wait(lock);
    }
}

Compiler version is

    gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3

running on Ubuntu Raring.

libpthread is:

    libpthread.so.0 (libc6,x86-64, OS ABI: Linux 2.6.24) =>
/lib/x86_64-linux-gnu/libpthread.so.0


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]