Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions listings/listing_8.11.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
#include <future>
#include <algorithm>
#include <vector>
struct join_threads
{
join_threads(std::vector<std::thread>&)
{}

class join_threads {
public:
join_threads(std::vector<std::thread> &threads) : threads_(threads) { }

~join_threads()
{
for (auto &t : threads_) {
if (t.joinable()) { t.join(); }
}
}

private:
std::vector<std::thread> &threads_;
};

template<typename Iterator>
Expand All @@ -24,7 +34,7 @@ void parallel_partial_sum(Iterator first,Iterator last)
std::partial_sum(begin,end,begin);
if(previous_end_value)
{
value_type& addend=previous_end_value->get();
value_type const& addend=previous_end_value->get();
*last+=addend;
if(end_value)
{
Expand Down Expand Up @@ -57,7 +67,7 @@ void parallel_partial_sum(Iterator first,Iterator last)
unsigned long const length=std::distance(first,last);

if(!length)
return last;
return;

unsigned long const min_per_thread=25;
unsigned long const max_threads=
Expand Down