c++ - 使用 std::async 同时更新子数组
问题描述
我正在尝试通过将其拆分为较小的数组来同时更新游戏循环中的数组
//sample code but 'arr' can be of any type
const int size = 1000000;
double arr[size];
while(running)
{
double dt = delta();
auto a = std::async([&](double tdt)
{
for(int i = 0; i < size / 2; i++)
arr[i] *= tdt;
}, dt);
auto b = std::async([&](double tdt)
{
for(int i = size / 2; i < size; i++)
arr[i] *= tdt;
}, dt);
/*do something with arr after*/
}
但我不确定我在这里做什么。
解决方案
推荐阅读
- javascript - 下面的代码适用于函数声明,但不适用于函数表达式
- c# - C# 异步后续调用返回现有任务
- python-3.x - python pandas中列表中几列的groupby行
- excel - 使用数组变量中的工作表数据创建图表
- php - 没有内置函数的数组键比较
- gradle - 在本地或 CI 中构建时如何在 Gradle 中的存储库之间切换
- docker - 在 Ubuntu Docker 容器中安装 Informix CSDK
- c++ - 为什么下面班级的大小是8
- linux - 用于 linux Debian 和 Arch 的 Docker 撰写文件
- android - Kotlin 多平台使用动态交付?