简体   繁体   English

内存障碍解决iOS ARM弱内存写入排序?

[英]Memory barriers to solve iOS ARM weak memory write ordering?

The ARM processors in iOS devices are reported to not to enforce the ordering of memory writes. 据报道,iOS设备中的ARM处理器不会强制执行内存写入顺序。 This means that if one processor writes a data struct or array and then updates a valid flag, another processor could see the updated valid flag before the data gets to memory, and thus read garbage. 这意味着如果一个处理器写入数据结构或数组然后更新有效标志,则另一个处理器可以在数据到达内存之前看到更新的有效标志,从而读取垃圾。 This is true even if the flag variable is small (atomic sized) and declared volatile. 即使标志变量很小(原子大小)并声明为volatile,也是如此。

Is there any way (in Swift or Objective C) to tell Xcode to compile in some ARM memory barrier instructions, intrinsics, or equivalent calls, to guarantee that data is written to memory (as visible to other processors on the same chip) before subsequent valid flag updates are issued? 是否有任何方法(在Swift或Objective C中)告诉Xcode在一些ARM内存屏障指令,内在函数或等效调用中编译,以保证数据被写入内存(对于同一芯片上的其他处理器可见)发布有效的国旗更新?

This is for real-time code where taking locks in real-time callbacks is not permitted. 这适用于实时代码,不允许在实时回调中获取锁定。

Look at libkern/OSAtomic.h which should include everything you need. 查看libkern / OSAtomic.h,其中应包含您需要的所有内容。

Or look at whatever the latest C and C++ Standard support; 或者查看最新的C和C ++标准支持; that will work on iOS as well. 这也适用于iOS。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM