当前位置: 首页 > news >正文

Unity dots IJobParallelFor并行的数据写入问题

Unity dots IJobParallelFor并行的数据写入问题

[BurstCompile]  
public struct IncrementJob : IJobParallelFor  
{  [ReadOnly] public NativeArray<int> baseValues;  public NativeArray<int> resultValues;   public void Execute(int index)  {resultValues[index+1]=5;}
}

上面的写法会报ReadWriteBuffers are restricted to only read & write the element at the job index错误,这是出于性能和线程安全的考虑,Unity Job System限制了每个Job只能访问或修改由Job索引指定的单个元素,因此这里非index索引下的数据写入收到了限制。

解决方案一

对于接触限制的数据加入NativeDisableParallelForRestriction

[BurstCompile]  
public struct IncrementJob : IJobParallelFor  
{  [ReadOnly] public NativeArray<int> baseValues;  [NativeDisableParallelForRestriction] public NativeArray<int> resultValues;   public void Execute(int index)  {resultValues[index+1]=5;}
}
解决方案二

只访问index索引下的数据

[BurstCompile]  
public struct IncrementJob : IJobParallelFor  
{  [ReadOnly] public NativeArray<int> baseValues;  public NativeArray<int> resultValues;   public void Execute(int index)  {resultValues[index]=5;}
}
http://www.lryc.cn/news/418628.html

相关文章:

  • 媒体资讯视频数据采集-yt-dlp-python实际使用-下载视频
  • MySQL 8
  • Android进阶之路 - app后台切回前台触发超时保护退出登录
  • 论文阅读笔记:Semi-supervised Semantic Segmentation with Error Localization Network
  • Flink开发语言选择:Java vs Scala,哪种更适合你的项目?
  • 轻空间成功完成陕西渭南砂石料场气膜仓项目
  • pikachu~文件下载漏洞
  • MTK Android12 关机界面全屏展示
  • 初识云计算
  • golang sync.Cond实现读写锁
  • 从通用到定制:营销Agent如何跨越数据鸿沟,实现对话SOP的个性化飞跃
  • 设计模式-单例设计模式
  • 23_windows 使用sqlmap、kali使用sqlmap,SQL注入、sqlmap自动注入
  • WPF学习(12)-Image图像控件+GroupBox标题容器控件
  • 【Linux】基础IO认知
  • 7. Kubernetes核心资源之Service服务实战
  • 《向量数据库指南》——企业采用非结构化数据的场景及其深远影响
  • Linux内核编程(十二)热插拔
  • 七夕警示:探索社工库与网络搜索下的个人隐私泄露与保护策略
  • Redis-哨兵监控(sentinel)
  • RISC-V反汇编调试记录分享
  • python上下文管理器 with的使用
  • 24/8/8算法笔记 决策树构建鸢尾花
  • 数据库扩展新篇章:主流分库分表中间件全解析
  • python看图片猜价格游戏,frame 和PhotoImage的使用
  • 未来展望:等保测评在网络安全领域的持续创新与发展
  • 构建深度学习驱动的多目标检测系统:YOLO模型及应用
  • 算法刷题笔记 染色法判定二分图(染色法例题 C++实现)
  • 在Ubuntu上安装OpenBLAS和Eigen
  • Vue前端面试基础(一)