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();
103 T* mid = m_data.get();
106 T*
end = m_data.get();
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);
156 for(
int step = 1; step <= exponent; step++)
161 int partition_size = 1 << step;
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)
T inplace_merge(T...args)
int main(int argc, char *const argv[])
unsigned long get_ms_diff(boost::xtime &start, boost::xtime &end)
bool operator<(const image &l) const
boost::shared_array< T > m_data
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