stm实现问题
嘿伙计们,
在某些时候,我认为这些 stm 实现(我使用过一点点的多元宇宙......)被过度炒作了。因为在某些时候他们使用 CAS,这为他们提供了操作的原子性。如果我直接使用 CAS 而不是使用这些实现会怎样?虽然我同意这些实现也可能提供其他功能,但是如果我可以获得相同的性能并且没有很多功能可以使用,那么我应该直接使用 CAS 而不是使用 multi-verse 或 scala 或其他实现吗?< br> 嘿,伙计们,当您使用这些 stm 实现而不是 CAS 时,您是否注意到任何性能提升?因为当我运行(在multiverse doc和atomicInteger JAVA中给出)atomicCounter时,我在atomicInteger中获得了比在multiverse中更好的性能。那么,stm 的基础是 CAS 吗? _
Hey guys,
At some point i think that these stm implementation ( multiverse which i have used a little bit... ), are over-hyped. Because at some point they uses CAS which is providing them atomicity of operations. What if i use CAS directly instead of using these implementation ? Though i agree that these implementation might be providing others features too, but If i can gain same performance and don't have a lot of features to use then should i use CAS directly instead of using multi-verse or scala or other implementations ?
Hey guys have you noticed any performance gain when you use those stm implementation than CAS ? since when i run ( given in multiverse doc and in atomicInteger JAVA) atomicCounter i gain better performance in atomicInteger than in multiverse. So is it like _the base of stm is CAS ? _
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
发布评论
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
STM 可以构建在许多不同的同步原语之上,但经常使用 CAS,因为它是最简单、最轻量级的选项,不会施加太多不必要的语义约束。
但是,是的,仅仅使用 CAS 操作会比使用除其他之外执行 CAS 操作的东西更快。
但它们有不同的目的。 CAS 允许您自动更新一些选择数据类型,STM 通常可用于任意类型。 STM 为您提供了更大事务范围的原子性(如果您的事务修改了 4 个不同的变量,则所有 4 个变量都会作为同一个原子操作提交。单个 CAS 只会原子地更新一个对象),并且它给出CAS 不存在隔离性和一致性保证。
最终,你无法将两者进行比较。这就像将车轮与汽车进行比较一样。是的,车轮更小、更轻,但那是因为它不提供与汽车相同的功能。
STM can be built on top of many different synchronization primitives, but CAS often used, because it's the simplest, most lightweight option which doesn't impose too many unnecessary semantic constraints.
But yes, just using a CAS operation is going to be faster than using something which, among other things performs a CAS operation.
But they serve different purposes. CAS allows you to atomically update a few select datatypes, STM can typically be used on arbitrary types. STM gives you atomicity on the much larger transaction scope (if your transaction modifies 4 different variables, all 4 are committed as the same atomic operation. A single CAS will only atomically update one object), and it gives you isolation and consistency guarantees that don't exist with CAS.
Ultimately, you can't compare the two. It's like comparing a wheel to a car. Yes, a wheel is smaller and more lightweight, but that's because it doesn't offer the same functionality as the car does.