18 #include <boost/thread/mutex.hpp>
19 #include <boost/smart_ptr.hpp>
50 boost::xtime::xtime_sec_t start_ms = start.sec * 1000 + start.nsec/1000000;
51 boost::xtime::xtime_sec_t end_ms = end.sec * 1000 + end.nsec/1000000;
52 return static_cast<unsigned long>(end_ms - start_ms);
59 image(
int content) : m_content(content) {}
70 boost::xtime_get(&xt, boost::TIME_UTC);
71 int duration = 1+(m_content % 4);
72 xt.nsec += 250 * 1000 * duration;
73 boost::thread::sleep(xt);
88 merge_job(boost::shared_array<T> data,
unsigned int position,
unsigned int length)
90 , m_position(position)
100 T*
begin = m_data.get();
101 std::advance(begin, m_position);
103 T* mid = m_data.get();
104 std::advance(mid, m_position + m_length/2);
106 T*
end = m_data.get();
107 std::advance(end, m_position + m_length);
109 std::inplace_merge(begin, mid, end);
127 print(
"MAIN: construct thread pool\n");
132 boost::xtime_get(&start, boost::TIME_UTC);
135 int data_len = 1 << exponent;
137 print(
"MAIN: sort array with "+
to_string(data_len) +
" elements.\n");
139 boost::shared_array<image> data(
new image[data_len]);
142 for(
int i = 0;
i < data_len;
i++)
144 data[
i] =
image((data_len -
i - 1) % 23);
161 int partition_size = 1 <<
step;
162 for(
int partition = 0; partition < data_len/partition_size; partition++)
165 boost::shared_ptr<merge_job<image> > job(
new merge_job<image>(data, partition*partition_size, partition_size));
174 boost::xtime_get(&end, boost::TIME_UTC);
178 print(
"\nMAIN: check if array is sorted... \n");
181 bool ascending =
true;
182 for(
int i = 0;
i < data_len-1;
i++)
184 if(data[
i+1] < data[
i])
192 print(
"\nMAIN: array is sorted\n");
196 print(
"\nMAIN: array is NOT sorted!\n");
void wait(size_t task_threshold=0) const
The current thread of execution is blocked until the sum of all active and pending tasks is equal or ...
merge_job(boost::shared_array< T > data, unsigned int position, unsigned int length)
string to_string(const T &value)
int main(int argc, char *const argv[])
auto begin(reverse_wrapper< T > &w)
unsigned long get_ms_diff(boost::xtime &start, boost::xtime &end)
bool operator<(const image &l) const
boost::shared_array< T > m_data
auto end(reverse_wrapper< T > &w)
disable_if< is_void< typename result_of< Function() >::type >, future< typename result_of< Function() >::type >>::type schedule(Pool &pool, const Function &task)
size_controller_type size_controller()
Gets the size controller which manages the number of threads in the pool.
boost::mutex m_io_monitor