比较和交换原子指令如何导致ABA问题。 [英] How Compare and Swap atomic instruction causes ABA Problem.

查看:198
本文介绍了比较和交换原子指令如何导致ABA问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近经历了一些用于实现互斥锁的原子指令。其中一些是1)比较和交换2)获取和协议

3)测试和设置4)在多处理器环境下加载链接和存储条件。



https://en.wikipedia.org/wiki/Compare-and-swap [ ^ ]

https ://en.wikipedia.org/wiki/ABA_problem



由于CAS(比较和交换)是原子指令,其他处理器如何与CAS交错。让我们说原子操作不适用于并发的多处理器实现,除非我们可以锁定内存(我不确定这是否正确)。但是如果我们从这个意义上讲,其他原子操作如Fetch和increement,Test和set也导致ABA问题吧?这真令人困惑。我的理解是原子指令不会在中间中断,但是在原子指令期间内存不会被锁定?其他处理器可以读写内存吗?



can有人澄清我的困惑吗?

I have recently gone through some of the atomic instructions which are used to implement mutual exclusive locks. Some of them are 1) compare and swap 2) Fetch and Increement
3) Test and Set 4) Load Link and Store conditional under multiprocessor environment.

https://en.wikipedia.org/wiki/Compare-and-swap[^]
https://en.wikipedia.org/wiki/ABA_problem

Since CAS(compare and swap) is an atomic instruction, how others processors will interleave with CAS. Lets say atomic actions don’t work for multiprocessor implementations of concurrency unless we can lock memory(I am not sure this is right or not).But if we take in that sense , other atomic operations like Fetch and increement, Test and set also cause ABA problem right? This is really confusing. What my understanding is that atomic instructions are not interrupted in the middle, but memory will not be locked during atomic instruction?can other processor read and write the memory?

can someone clarify my confusion?

推荐答案

原子指令是不可中断的,所以它应该能够测试和修改内存位置,而不需要任何其他操作来获取相同的内存。例如,test和set将读取内存中的某个位置,如果可用,则将其设置为固定值。发生这种情况时,即使在多处理器配置中也不允许其他指令访问相同的内存位置。
An atomic instruction is not interruptible, so it should be able to test and modify a memory location without any other operation acessing the same one. For example, test and set will read a location in memory, and if available set it to a fixed value. While this is happening no other instruction is allowed to access the same memory location, even in a multi-processor configuration.


这篇关于比较和交换原子指令如何导致ABA问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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