由于C++ 11没有future.then
我已经开始使用来自Microsoft PPL
库的concurrency::task
。它大部分时间都很好用。执行。然后不加延迟
但是,现在我处于GPGPU的状态,所以如果在GPU空闲的时候在PPL
调度程序中计划的延续会导致不必要的延迟。
我的问题是,是否有任何可能的解决方法concurrency::task
和concurrency::task::then
让他们直接执行。
根据我的理解,定期计划的任务在大多数情况下会由于缓存效率原因立即执行。但是,对于已使用concurrency::task_completion_event
从显式线程(即GPU线程)调度的任务,情况并非如此。
的我在做什么一个例子:
template<typename F>
auto execute(F f) -> concurrency::task<decltype(f())>
{
concurrency::task_completion_event<decltype(f())> e;
gpu_execution_queue_.push([=]
{
try
{
e.set(copy(f())); // Skipped meta-template programming for void.
}
catch(...)
{
e.set_exception(std::current_exception());
}
});
// Any continuation will be delayed since it will first be
// enqueued into the task-scheduler.
return concurrency::task<decltype(f())>(std::move(e));
}
void foo()
{
std::vector<char> data /* = ... */;
execute([=]() -> texture
{
return copy(data)
})
.then(concurrency::task<texture> t)
{
return execute([=]
{
render(t.get());
});
})
.get();
}
您的问题似乎从需要多个干根据任务类型(要执行的代码),代表不同类型的计算资源(CPU和GPU)的任务队列。在PPL中,这将涉及使用[Scheduler class](http://msdn.microsoft.com/zh-cn/library/dd492385.aspx)。 – rwong