比较和交换vs测试和设置 [英] compare and swap vs test and set

查看:458
本文介绍了比较和交换vs测试和设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以向我解释多线程中上述操作的工作和差异吗?

Could someone explain to me the working and differences of above operations in multi-threading?

推荐答案

test-and-set 修改内存位置的内容,并将其旧值作为单个原子操作返回。

test-and-set modifies the contents of a memory location and returns its old value as a single atomic operation.

compare-and-swap 以原子方式将内存位置的内容与给定值进行比较,

compare-and-swap atomically compares the contents of a memory location to a given value and, only if they are the same, modifies the contents of that memory location to a given new value.

以粗体标示的差异。

The difference marked in bold.

这篇关于比较和交换vs测试和设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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