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 ? _
Hey guys, At some point i think that these stm implementation ( multiverse which
Share
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.