Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

STM.NET versus Clojure STM

Tags:

c#

.net

clojure

stm

I'm wondering how is that possible that Clojure has implemented Software Transactional Memory and doesn't see any problem with that while Microsoft didn't finish its work for C# and noticed some problems which make it unpractical to implement STM described here: http://www.bluebytesoftware.com/blog/2010/01/03/ABriefRetrospectiveOnTransactionalMemory.aspx

Any idea please?

like image 255
user1121956 Avatar asked Jun 24 '13 16:06

user1121956


2 Answers

Clojure started on STM from nearly the beginning of the language which influenced the language design and how the language is used so as to make their STM practical. C# had to start with both an existing language and existing ways of using it which makes for a more difficult problem. The most seemingly important distinction is Clojure's STM starts with immutable data at the core of the language and then builds the concept of identity ontop of that and STM on top of the concept of identities. It's also worth noting that their are many different kinds of STM and clojure's STM is very different.

like image 169
Arthur Ulfeldt Avatar answered Oct 17 '22 11:10

Arthur Ulfeldt


The there are many different approaches to STM. It's a very broad topic like "type systems": one approach can easily succeed while other approaches fail for various different reasons.

Clojure's STM has a few design decisions that make it IMHO more practical and effective than previous approaches:

  • It doesn't try to protect arbitrary data with STM - you have to use special managed references like (ref and similar). This makes it a much simpler and more focused design than many earlier STM approaches (this includes Microsoft's approach, at least as described in the above-linked article)
  • It uses multi-version concurrency control with immutable data. This makes transaction handling much more effective and practical. In particular, it means that non-transactional reads don't require any locking, which is a huge performance win....
  • It's done in the context of a functional language - in particular, the fact that most code in Clojure is side-effect free by default makes it much easier to apply such techniques like transaction retries.

As a result of these design decisions, Clojure's STM is a very different beast from previous STM approaches, and I think succeeds because of its novel design. The video below is a bit old but excellent if you want an overview of how it works:

http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey

like image 21
mikera Avatar answered Oct 17 '22 10:10

mikera