I am confused about something about C ++ 11 std::future . I want to dynamically balance the workload, so if there are several processors in standby mode, I create std::future with std::async to separate the remaining data. It works great.
std::future<int> f[MAX_CHILD]; for ( each data item ){ if ( found_idle_processor ) f[i] = std::async( ... ); process(); }
But sometimes, when some special data elements were found, all other data will be discarded, and the program should immediately give the final result, then another task will be launched.
std::future<int> f[MAX_CHILD]; for ( each data item ){ if ( found_idle_processor ) f[i] = std::async( ... ); process(); if ( found_special_item ) return final_result; }
But the f created out of my control, do they still work after returning? how can i finish them to free up the processor time they used?
source share