<html>
    <head>
      <base href="http://llvm.org/bugs/" />
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW --- - Simple c++ program using lldb hangs in std::condition_variable desctructor when linked with -lpthreads on linux with gcc"
   href="http://llvm.org/bugs/show_bug.cgi?id=21553">21553</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Simple c++ program using lldb hangs in std::condition_variable desctructor when linked with -lpthreads on linux with gcc
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>lldb
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>unspecified
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>Linux
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>All Bugs
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>lldb-dev@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>sbest@blueshiftinc.com
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>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.</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are the assignee for the bug.</li>
      </ul>
    </body>
</html>