17 #include <boost/smart_ptr.hpp> 18 #include <boost/thread/mutex.hpp> 47 boost::xtime::xtime_sec_t start_ms = start.sec * 1000 + start.nsec / 1000000;
48 boost::xtime::xtime_sec_t end_ms = end.sec * 1000 + end.nsec / 1000000;
49 return static_cast<unsigned long>( end_ms - start_ms );
56 image(
int content ) : m_content( content ) {}
64 boost::xtime_get( &xt, boost::TIME_UTC );
65 int duration = 1 + ( m_content % 4 );
66 xt.nsec += 250 * 1000 * duration;
67 boost::thread::sleep( xt );
81 merge_job( boost::shared_array<T> data,
unsigned int position,
unsigned int length )
82 : m_data( data ), m_position( position ), m_length( length )
91 T*
begin = m_data.get();
94 T* mid = m_data.get();
97 T*
end = m_data.get();
115 print(
"MAIN: construct thread pool\n" );
118 boost::xtime_get( &start, boost::TIME_UTC );
121 int data_len = 1 << exponent;
123 print(
"MAIN: sort array with " +
to_string( data_len ) +
" elements.\n" );
125 boost::shared_array<image> data(
new image[data_len] );
128 for (
int i = 0; i < data_len; i++ ) {
129 data[i] =
image( ( data_len - i - 1 ) % 23 );
140 for (
int step = 1; step <= exponent; step++ ) {
144 int partition_size = 1 << step;
147 boost::shared_ptr<merge_job<image>> job(
157 boost::xtime_get( &end, boost::TIME_UTC );
161 print(
"\nMAIN: check if array is sorted... \n" );
164 bool ascending =
true;
165 for (
int i = 0; i < data_len - 1; i++ ) {
166 if ( data[i + 1] < data[i] ) {
172 print(
"\nMAIN: array is sorted\n" );
174 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