Prev | Next | multi_atomic_two_takedown |
ok = multi_atomic_two_takedown(square_root)
vector<double>& square_root
The input value of
square_root
does not matter.
Upon return,
it has the same size and is the element by element square root of
y_squared
.
bool ok
If it is false,
multi_atomic_two_takedown
detected an error.
namespace { bool multi_atomic_two_takedown(vector<double>& square_root) { bool ok = true; ok &= thread_alloc::thread_num() == 0; size_t num_threads = std::max(num_threads_, size_t(1)); // // extract square roots in original order square_root.resize(0); for(size_t thread_num = 0; thread_num < num_threads; thread_num++) { // results for this thread size_t n = work_all_[thread_num]->square_root->size(); for(size_t i = 0; i < n; i++) square_root.push_back((* work_all_[thread_num]->square_root )[i]); } // // go down so that free memory for other threads before memory for master size_t thread_num = num_threads; while(thread_num--) { // check that this tread was ok with the work it did ok &= work_all_[thread_num]->ok; // // run destructor on vector object for this thread delete work_all_[thread_num]->y_squared; delete work_all_[thread_num]->square_root; // // run destructor on function object for this thread delete work_all_[thread_num]->fun; // // delete problem specific information void* v_ptr = static_cast<void*>( work_all_[thread_num] ); thread_alloc::return_memory( v_ptr ); // // check that there is no longer any memory inuse by this thread if( thread_num > 0 ) { ok &= 0 == thread_alloc::inuse(thread_num); // // return all memory being held for future use by this thread thread_alloc::free_available(thread_num); } } return ok; } }