-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Closed as duplicate of#13102
Closed as duplicate of#13102
Copy link
Labels
bugzillaIssues migrated from bugzillaIssues migrated from bugzillac++11duplicateResolved as duplicateResolved as duplicate
Description
| Bugzilla Link | 16969 |
| Version | 3.2 |
| OS | Linux |
| Attachments | quick_sort function template |
| Reporter | LLVM Bugzilla Contributor |
| CC | @DougGregor |
Extended Description
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: posixMetadata
Metadata
Assignees
Labels
bugzillaIssues migrated from bugzillaIssues migrated from bugzillac++11duplicateResolved as duplicateResolved as duplicate