[Bug 21553] New: Simple c++ program using lldb hangs in std::condition_variable desctructor when linked with -lpthreads on linux with gcc

Bug ID 21553
Summary Simple c++ program using lldb hangs in std::condition_variable desctructor when linked with -lpthreads on linux with gcc
Product lldb
Version unspecified
Hardware PC
OS Linux
Status NEW
Severity normal
Priority P
Component All Bugs
Assignee lldb-dev@cs.uiuc.edu
Reporter sbest@blueshiftinc.com
Classification Unclassified

Consider the following simple stand-alone c++ that does nothing other than
initialize lldb, then use a std::condition_variable.

#include <iostream>
#include <condition_variable>
#include <mutex>

#include "lldb/API/LLDB.h"

int main(int argc, char** argv) 
{
    lldb::SBDebugger::Initialize();

    {
        std::condition_variable g_condition;
        {
            std::mutex g_mutex;
            std::unique_lock<std::mutex> lock(g_mutex);
            g_condition.wait_for(lock, std::chrono::seconds(1));

            std::cout << "going out of scope 1\n";        
        }
        std::cout << "going out of scope 2\n";        
    }
    std::cout << "done\n";
}

When the program is built on Unbuntu 14.04, x86_64 with the following command
line:

g++  hang.cpp -g -O0 -m64 -std=c++11 -Ipath_to_lldb/include
-Lpath_to_lldb_build/lib -llldb -lpthread -o "hang"

Remember to also set environment variable: 
export LD_LIBRARY_PATH=path_to_lldb_build/lib

Program hangs after printing "going out of scope 2", and never prints "done". 
If I interrupt the hang, it is waiting on a mutex inside the
std::condition_variable destructor.

Remove "-lpthread" from link flags and program works no problem. 
std::condition_variable is included by "-std=c++11", but this behavior is
platform dependent.

Chaoren Lin changed bug 21553

What | Removed | Added |

  • | - | - |
    Status | NEW | RESOLVED |
    CC | | chaorenl@google.com |
    Resolution | — | WORKSFORME |

Comment # 1 on bug 21553 from Chaoren Lin

Not reproducible. Compiling the c++ code provided with the exact instructions
on Ubuntu 14.04 x86_64 does not hang.