I have a vector of unsigned variables of the type:
vector<unsigned> a;
a.push_back(5); a.push_back(3); a.push_back(2); a.push_back(1);
a.push_back(12); a.push_back(4); a.push_back(20); a.push_back(11);
a.push_back(13); a.push_back(7); a.push_back(23); a.push_back(21);
Now I want to create 3 threads such that each thread sorts 4 values in the vector. E.g.
Thread 1: a[0],a[1],a[2],a[3]. After sorting their values become: 1,2,3,5
Thread 2: a[4],a[5],a[6],a[7]. After sorting their values become: 4,11,12,20
Thread 3: a[8],a[9],a[10],a[11]. After sorting their values become: 7,13,21,23
After all the threads have finished sorting, I intend to notify that the values are now sorted. Is it possible to do the same in c++ using pthread if yes then how. I am using gcc 4.4. I know it is possible to do the same sequentially but I am curious to know if it is possible to sort these threads in a multi-threaded way?
EDIT: I can not use std::async as I am working with gcc version 4.4. and I am trying to include this logic in an old code which has been coded before c++11. Therefore, I can not use c++11.