Reputation: 9363
I would like to write a multithreaded merge sort using threadpool and hence downloaded the boost library. I am newbie to c++ and has difficulty in understanding how to run the example programs given with the source. here is the source from where i downlaoded.. http://threadpool.sourceforge.net/ .... It is there in the Download section...Any help is appreciated.
Upvotes: 1
Views: 1396
Reputation: 2412
Another tool for managing threads would be TBB Intel Thread Building Blocks. There you even already have an implementation of merge sort, see "tbb/parallel_sort.hpp" (however this implementation is not very efficient as it needs minimum O(n) time independent of number of threads).
Upvotes: 2
Reputation: 5538
I'm not familiar with that particular threadpool library (b.t.w. it's not part of the Boost), but the general concept of threadpool is very simple. The class must have something like enqueue(std::function<void()> fn);
interface and all you need is to wrap your function to get desired function object, which is usually done either with std::bind
or lambda function. Threadpool will keep your function objects in a queue until it has an available thread to execute it; at that point it simply calls fn()
. Regarding parallelizing sorting you can write a quicksort version, which lends itself very well for parallelization: http://en.wikipedia.org/wiki/Quicksort
P.S. std::function
, corresponding std::bind
, and lambda functions are part of C++0x, you can find substitutes in Boost as well.
Upvotes: 1
Reputation: 54148
OpenMP would be a better bet for your requirements that self-managed threads. There's a merge sort example included in this overview.
Upvotes: 0