InterlockedExchange和内存对齐 [英] InterlockedExchange and memory alignment

查看:146
本文介绍了InterlockedExchange和内存对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Microsoft说InterlockedExchange需要内存对齐感到困惑,但是,英特尔文档说LOCK不需要内存对齐. 我在想什么吗? 谢谢

I am confused that Microsoft says memory alignment is required for InterlockedExchange however, Intel documentation says that memory alignment is not required for LOCK. Am i missing something, or whatever? thanks

平台SDK:DLL,进程和线程 互锁交换

Platform SDK: DLLs, Processes, and Threads InterlockedExchange

Target参数指向的变量必须在32位边界上对齐;否则,此功能将在多处理器x86系统和所有非x86系统上表现出不可预测的作用

The variable pointed to by the Target parameter must be aligned on a 32-bit boundary; otherwise, this function will behave unpredictably on multiprocessor x86 systems and any non-x86 systems.

  • LOCK指令 使处理器的LOCK#信号在执行随附指令的过程中被声明(将指令转换为原子指令).在多处理器环境中,LOCK#信号可确保在声明该信号时处理器专有使用任何共享内存.

  • LOCK instruction Causes the processor’s LOCK# signal to be asserted during execution of the accompanying instruction (turns the instruction into an atomic instruction). In a multiprocessor environment, the LOCK# signal insures that the processor has exclusive use of any shared memory while the signal is asserted.

LOCK前缀的完整性不受存储字段对齐的影响. 观察到任意锁定的字段的内存锁定.

The integrity of the LOCK prefix is not affected by the alignment of the memory field. Memory locking is observed for arbitrarily misaligned fields.

P6和更新的处理器家族中的内存顺序

Memory Ordering in P6 and More Recent Processor Families

锁定的指令具有全部订单.

软件控制的总线锁定

总线锁定的完整性不受存储字段对齐的影响.对于更新整个操作数所必需的总线周期,遵循LOCK语义..但是,建议锁定访问在其自然边界上对齐,以提高系统性能: •8位访问的任何边界(锁定或其他). •16位边界,用于锁定字访问. •32位边界,用于锁定双字访问. •64位边界用于锁定四字访问.

The integrity of a bus lock is not affected by the alignment of the memory field. The LOCK semantics are followed for as many bus cycles as necessary to update the entire operand. However, it is recommend that locked accesses be aligned on their natural boundaries for better system performance: •Any boundary for an 8-bit access (locked or otherwise). •16-bit boundary for locked word accesses. •32-bit boundary for locked doubleword accesses. •64-bit boundary for locked quadword accesses.

推荐答案

从前,Microsoft曾经在x86以外的处理器(例如MIPS,PowerPC和Alpha)上支持WindowsNT.这些处理器都需要对它们的互锁指令进行对齐,因此Microsoft在其规范中提出了要求,以确保这些原语可移植到不同的体系结构中.

Once upon a time, Microsoft supported WindowsNT on processors other than x86, such as MIPS, PowerPC, and Alpha. These processors all require alignment for their interlocked instructions, so Microsoft put the requirement in their spec to ensure that these primitives would be portable to different architectures.

这篇关于InterlockedExchange和内存对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆