关闭

Acquire and Release Semantics

847人阅读 评论(0) 收藏 举报

Acquire and Release Semantics

1(共 3)对本文的评价是有帮助 评价此主题

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 InterlockedXxxAcquire and 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 to InterlockedIncrement.

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

0
0

猜你在找
【直播】机器学习&数据挖掘7周实训--韦玮
【套餐】系统集成项目管理工程师顺利通关--徐朋
【直播】3小时掌握Docker最佳实战-徐西宁
【套餐】机器学习系列套餐(算法+实战)--唐宇迪
【直播】计算机视觉原理及实战--屈教授
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之矩阵--黄博士
【套餐】微信订阅号+服务号Java版 v2.0--翟东平
【直播】机器学习之凸优化--马博士
【套餐】Javascript 设计模式实战--曾亮
查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:1241201次
    • 积分:12267
    • 等级:
    • 排名:第1154名
    • 原创:89篇
    • 转载:472篇
    • 译文:2篇
    • 评论:114条
    文章分类
    最新评论