STM.NET on DevLabs
Today we made available STM.NET on MSDN DevLabs. STM.NET is an experimental enhanced version of .NET Framework 4 Beta 1 that enables software transactional memory for C# programmers.
Transactional memory is a technology that frees developers from worrying about the mechanics of fine-grained locking and synchronization in multithreaded applications by providing transactional semantics for reading and writing to memory. It enables developers to focus on application logic instead of the details of memory I/O when building multi-core and many-core programs.
STM.NET makes it easy to declare a region of code as atomic. Simply write a function or lambda containing the code that you’d like to transact and pass it to the Atomic.Do delegate. Just like SQL code in a database transaction, this block of code will run as if isolated from other transacted blocks and either it completes successfully or rolls back the complete transaction if there is an error, all without you having to explicitly lock anything.
How Does it Work?
The .NET Framework’s just-in-time compiler rewrites the code within an atomic block to use transactional memory. As a result, a significant amount of .NET code works without changes, including code that uses locks. STM.NET also provides integration with System.Transactions so you can coordinate your atomic memory operations with existing transactional resource managers like MSMQ.
One of the best aspects of STM.NET is its integration with Visual Studio tooling. STM.NET works with the Visual Studio 2008 debugger to allow you to see the values of transacted variables as they appear while running inside the Atomic.Do delegate as well as their values as they appear outside.