Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > ANN: Axon.STM 1.0.0 (beta) Minimalistic Software Transactional Memory

Thread Tools

ANN: Axon.STM 1.0.0 (beta) Minimalistic Software Transactional Memory

Michael Sparks
Posts: n/a

I've packaged up the minimal STM discussed over the past couple of days as a
standalone package which I've now uploaded

Getting it
You can download a beta test version here:

Previewing it
You can look at the sourcecode online here:

Installing it
~ > tar zxf Axon.STM-1.0.0.tar.gz
~ > cd Axon.STM-1.0.0/
~ > sudo python install

What IS it?
Software Transactional Memory (STM) is a technique for allowing multiple
threads to share data in such a way that they know when something has gone
wrong. It's been used in databases (just called transactions there really)
for some time and is also very similar to version control. Indeed, you can
think of STM as being like variable level version control.

Note: Because this is NOT intended to be persistent, this is not an ACID
store because it doesn't support the D - durability across a crash. (after
all, we don't save the state to disk) (The other aspects atomicity,
consistency & isolation are supported though)

I've written this to allow a part of Kamaelia to share & manage a dictionary
of atomic values between threads simply, and as a result this code is also
going into mainline Kamaelia. (Specifically into Axon Kamaelia's core)

However STM is something that should hopefully be of use to others doing
concurrent *things* whether or not they're using kamaelia, hence this stand
alone release.

This stand alone release should *not* be used alongside mainline Axon yet.
(Well you can, as long as you reinstall your Axon over the top, but that's

Why is it useful?
[ please skip this (or correct me if you understand concurrency
already ]

Why do you need it? Well, in normal code, Global variables are generally
shunned because it can make your code a pain to work with and a pain to be
certain if it works properly. Even with linear code, you can have 2 bits of
code manipulating a structure in surprising ways - but the results are
repeatable. Not-properly-managed-shared-data is to threaded systems as
not-properly-managed-globals are to normal code. (This code is one way of
helping manage shared data)

Well, with code where you have multiple threads active, having shared data
is like an even nastier version of globals. Why? Well, when you have 2 (or
more) running in parallel, the results of breakage can become hard to
repeat as two pieces of code "race" to update values.

With STM you make it explicit what the values are you want to update, and
only once you're happy with the updates do you publish them back to the
shared storage. The neat thing is, if someone else changed things since you
last looked, you get told (your commit fails), and you have to redo the
work. This may sound like extra work (you have to be prepared to redo the
work), but it's nicer than your code breaking

The way you get that message is the .commit raises a ConcurrentUpdate

Also, it's designed to work happily in code that requires non-blocking
usage - which means you may also get a "BusyRetry" exception under load. If
you do, you should as the exception suggests retry the action that you just
tried. (With or without restarting the transaction)

Apologies if that sounds too noddy

Docs for it

Using It

# Initialising a Store
from Axon.STM import Store

S = Store()

# Single values
greeting = S.usevar("hello")
print repr(greeting.value)
greeting.set("Hello World")

# Groups of values
D = S.using("account_one", "account_two", "myaccount")

D = S.using("account_one", "account_two", "myaccount")

Take your pick of MPL V1.1, GPL 2.0, LGPL 2.1

Feedback is very welcome, preferably via email to the Kamaelia List
* Removed)

Feedback especially regarding bugs and logical errors is particularly
welcome. (hopefully there aren't any - but it's always hard to spot your

Many thanks to Fuzzyman, Duncan Booth, John J Lee & Sylvain Hellegouarch for
feedback whilst I was prototyping this.

Best Regards,

Michael Sparks, Kamaelia Project

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Announcement: depikt - the minimalistic python gate to gtk DreiJane Python 0 11-20-2009 10:51 AM
MiLi: minimalistic libraries dgutson C++ 0 04-01-2009 12:29 PM
New interesting application of Transactional Memory forsingle-threading Dmitriy V'jukov C++ 3 10-23-2008 08:24 PM
Minimalistic Software Transactional Memory Michael Sparks Python 9 01-11-2008 02:28 AM
ANN: Axon.STM 1.0.1 (release) Minimalistic Software TransactionalMemory (with examples) Michael Sparks Python 0 12-24-2007 11:56 AM