2

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 ? _

4

2 に答える 2

2

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.

于 2011-07-07T09:18:54.767 に答える
1

これらの実装を使用する代わりにCASを直接使用するとどうなりますか?

あなたはそれを行うことができますが、それはほとんどの問題に対して低レベルです。CASにドロップダウンすることは、すべてをアセンブリで記述するようなものです。確かに、それは可能ですが、時間を有効に活用することはできません。

課題は、コンピューターではなく、問題の抽象化のレベルにより正確に一致するものを見つけることです。

明らかに、下部にあるソフトウェアTMは、ハードウェアTMまたはアトミックロック操作のいずれかで実装する必要があります。ロールバックと衝突回避の追加のセマンティクスは、別々に実行できます。アトミックコンペアアンドスワップのみが必要な場合、STMは必要以上のものです。ドロップダウンして、ミューテックスまたはセンパフォア、あるいはCAS命令に近い他の共有メモリ抽象化を使用します。

于 2011-06-22T13:46:18.367 に答える