请问HN:有人能做一个CAS,只检查x86/ARM上的最后一位吗?
大家好,我在这里考虑做一些工作,注意到没有一种操作可以基于最后一位进行原子比较/交换。
应该有一条指令,允许你在最后一位为0的情况下更新一个64位的值。
这里的想法是,你可以在指针值未锁定的情况下原子性地交换它们。
2^63是一个非常大的数字,足以表示宇宙中几乎所有的数据。如果我们允许对最后一位进行原子比较交换,或者类似于检查最后一位是否为0,允许写入,否则不允许,这将使编程变得更加简单。
谢谢!
查看原文
Guys/gals, I was thinking about doing some work here and I noticed there's no operation that allows a atomic compare/exchange based on the last bit.<p>There should be an instruction that allows you to do an update of a 64 bit value only if the last bit is a 0.<p>The idea here is you would be able to swap pointer values atomically only if they were unlocked.<p>2^63 is such a huge number, it is sufficient to represent practically all the data in the universe. If we allowed an atomic compare exchange on the last bit, or something like check if the last bit is 0, allow the write, otherwise don't, it would make programming a lot easier.<p>Thanks!