<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 --- - "pure virtual method called" error with std::thread and template function"
   href="http://llvm.org/bugs/show_bug.cgi?id=16969">16969</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>"pure virtual method called" error with std::thread and template function
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>3.2
          </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>C++11
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>rodin.alexander@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>dgregor@apple.com, llvmbugs@cs.uiuc.edu
          </td>
        </tr>

        <tr>
          <th>Classification</th>
          <td>Unclassified
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=11084" name="attach_11084" title="quick_sort function template">attachment 11084</a> <a href="attachment.cgi?id=11084&action=edit" title="quick_sort function template">[details]</a></span>
quick_sort function template

I've created a multithreaded quick sort function:

#include <utility>
#include <thread>

template <typename Iterator>
void quick_sort(Iterator begin, Iterator end, int tc = 4) {
    if (begin < end - 1) {
        Iterator middle = end - 1;
        Iterator left = begin;

        while (left != middle) {
            if (*left > *middle) {
                --middle;
                std::swap(*middle, middle[1]);
                if (middle != left) 
                    std::swap(middle[1], *left);
            } else  
                ++left;
        }       

        if (tc > 1) {
            std::thread left_thread(quick_sort<Iterator>, begin, middle, tc /
2);
            std::thread right_thread(quick_sort<Iterator>, middle + 1, end, tc
/ 2);
            left_thread.join();
            right_thread.join();
        } else {
            quick_sort(begin, middle, 1);
            quick_sort(middle + 1, end, 1);
        }   
    }   
}   

When I run a test program with it, for example

int main() {
    double data[] = {0.840188, 0.394383, 0.783099, 0.798440, 0.911647,
0.197551, 0.335223, 0.768230, 0.277775, 0.553970, };
    quick_sort(data, sizeof(data) / sizeof(double));
}

the program fails:

$ ./sort
terminate called after throwing an instance of 'std::system_error'
  what():  Operation not permitted
Aborted (core dumped)

This code works fine with g++ 4.7.

clang information: 

$ clang++ --version
Ubuntu clang version 3.2-1~exp9ubuntu1 (tags/RELEASE_32/final) (based on LLVM
3.2)
Target: x86_64-pc-linux-gnu
Thread model: posix</pre>
        </div>
      </p>
      <hr>
      <span>You are receiving this mail because:</span>
      
      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>