Acquire and Release Semantics

An operation has acquire semantics if other processors will always see its effect before any subsequent operation's effect. An operation has release semantics if other processors will see every preceding operation's effect before the effect of the operation itself.

Consider the following code example:

 a++;
 b++;
 c++;

From another processor's point of view, the preceding operations can appear to occur in any order. For example, the other processor might see the increment of b before the increment of a.

Atomic operations, such as those that the InterlockedXxx routines perform, have both acquire and release semantics by default. However, Itanium-based processors execute operations that have only acquire or only release semantics faster than those that have both. Therefore, the system provides InterlockedXxxAcquireand InterlockedXxxRelease versions of some of the InterlockedXxx routines.

For example, the InterlockedIncrementAcquire routine uses acquire semantics to increment a variable. If you rewrote the preceding code example as follows:

 InterlockedIncrementAcquire(&a);
 b++;
 c++;

other processors would always see the increment of a before the increments of b and c.

Likewise, the InterlockedIncrementRelease routine uses release semantics to increment a variable. If you rewrote the code example once again, as follows:

 a++;
 b++;
 InterlockedIncrementRelease(&c);

other processors would always see the increments of a and b before the increment of c.

If the processor does not provide instructions that have only acquire or only release semantics, the system will use the corresponding routine that provides both types of semantics. For example, on x86 processors both InterlockedIncrementAcquire and InterlockedIncrementRelease are equivalent toInterlockedIncrement.

The following table lists the routines that have acquire-only and release-only variants.

InterlockedXxx Routine Acquire-Semantics-Only Version Release-Semantics-Only Version

InterlockedIncrement

InterlockedIncrementAcquire

InterlockedIncrementRelease

InterlockedDecrement

InterlockedDecrementAcquire

InterlockedDecrementRelease

InterlockedCompareExchange

InterlockedCompareExchangeAcquire

InterlockedCompareExchangeRelease

 

 

 

Send comments about this topic to Microsoft

Build date: 10/12/2013

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值