我对下面这个例子中的一个(未记录的)boost::basic_thread_pool executor
接口使用原因感到困惑,该例子摘自boost文档:
template<typename T>
struct sorter
{
boost::basic_thread_pool pool;
typedef std::list<T> return_type;
std::list<T> do_sort(std::list<T> chunk_data)
{
if(chunk_data.empty()) {
return chunk_data;
}
std::list<T> result;
result.splice(result.begin(),chunk_data, chunk_data.begin());
T const& partition_val=*result.begin();
typename std::list<T>::iterator divide_point =
std::partition(chunk_data.begin(), chunk_data.end(),
[&](T const& val){return val<partition_val;});
std::list<T> new_lower_chunk;
new_lower_chunk.splice(new_lower_chunk.end(), chunk_data,
chunk_data.begin(), divide_point);
boost::future<std::list<T> > new_lower =
boost::async(pool, &sorter::do_sort, this, std::move(new_lower_chunk));
std::list<T> new_higher(do_sort(chunk_data));
result.splice(result.end(),new_higher);
while(!new_lower.is_ready()) {
pool.schedule_one_or_yield();
}
result.splice(result.begin(),new_lower.get());
return result;
}
};
这个问题中涉及到的调用是
pool.schedule_one_or_yield();
。如果我理解正确,它表明一个提交的任务最终将被安排执行。如果是这样,难道不应该每个先前对boost::async(pool, &sorter::do_sort, this, std::move(new_lower_chunk));
的调用已经隐式地安排了提交的任务吗?我知道boost executor API是实验性的,但你知道为什么
schedule_one_or_yield
未记录在文档中吗?