在我的图形应用程序中,我想在另一个线程中生成批处理网格。因此我使用异步调用成员函数std::async
。
task = async(launch::async, &Class::Meshing, this, Data(...));
在我的更新循环中,我尝试检查线程是否准备好。如果是,我会将网格发送到视频卡并开始下一个线程。如果没有,我将跳过这些操作。
#include <future>
using namespace std;
class Class
{
public:
void Update()
{
if(task.finished()) // this method does not exist
{
Data data = task.get();
// ...
task = async(launch::async, &Class::Meshing, this, Data(/* ... */));
}
}
private:
struct Data
{
// ...
};
future<Data> task;
Data Meshing(Data data)
{
// ...
}
};
如何检查异步线程是否完成而不卡在更新功能中?