STMNet is an API for multithreaded computation in which shared data is synchronized without using locks. Threads synchronize by means of memory transactions, short-lived computations that either commit (take effect) or abort (have no effect). Transactions avoid the well-known problems of locking, including deadlock, priority inversion, and fault-intolerance. The STMNet is a software transactional memory package written in C#.
Quick start:
// Create STM Objects to be used by several threadspublicStmObject<int>myStmValue=StmCreateObject(5);publicStmObject<SomeObject>myStmObject=Stm.CreateObject(newSomeObject(initValue));// This method is called by a thread to do something...publicvoidDoSomething(){using(vartrans=Stm.BeginTransaction()){// Read the value of myStmValuevarv=myStmValue.Read();// Create and init a new SomeObjectvarnewObj=newSomeObject(v);myStmObject.Write(newObj);}if(Stm.Transaction.State==TransactionsState.Committed){// Transactions committed }if(Stm.Transaction.State==TransactionsState.Aborted){// Transactions aborted }}Transactions Delegate and Retry Delegate
// Create STM Objects to be used by several threadspublicStmObject<int>myStmValue=StmCreateObject(5);publicStmObject<SomeObject>myStmObject=Stm.CreateObject(newSomeObject(initValue));// Create a Transaction DelegatepublicvoidTransDelegate(Transactiontransaction){using(transaction){myStmValue.Write(2);// Create and init a new SomeObjectvarnewObj=newSomeObject(myStemValue.Read());myStmObject.Write(newObj);}}// Create a Retry DelegatepublicboolRetryDelegate(Transactiontransaction){returntransaction.RetryCount<3;}// Method to execute the transactionpublicvoidExecuteTransTest(){vartrans=Stm.ExecuteTransaction(TransDelegate,RetryDelegate);if(trans.State==TransactionsState.Committed){// Transactions committed }if(trans.State==TransactionsState.Aborted){// Transactions aborted }}- Objects that take part in an STM Transaction must implement IStmObject interface