[LLVMbugs] [Bug 16969] New: "pure virtual method called" error with std::thread and template function

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Thu Aug 22 07:50:21 PDT 2013


http://llvm.org/bugs/show_bug.cgi?id=16969

            Bug ID: 16969
           Summary: "pure virtual method called" error with std::thread
                    and template function
           Product: clang
           Version: 3.2
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++11
          Assignee: unassignedclangbugs at nondot.org
          Reporter: rodin.alexander at gmail.com
                CC: dgregor at apple.com, llvmbugs at cs.uiuc.edu
    Classification: Unclassified

Created attachment 11084
  --> http://llvm.org/bugs/attachment.cgi?id=11084&action=edit
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

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20130822/12772a91/attachment.html>


More information about the llvm-bugs mailing list