Software transactional memory (STM) is a mechanism for synchronization in concurrent programming, which can perform groups of memory operations atomically. Using transactional memory (implemented by optimistic synchronization) instead of locks removes the risk of a deadlock.
Questions tagged [stm]
190 questions
63
votes
6 answers
Any Real-World Experience Using Software Transactional Memory?
It seems that there has been a recent rising interest in STM (software transactional memory) frameworks and language extensions. Clojure in particular has an excellent implementation which uses MVCC (multi-version concurrency control) rather than a…

Daniel Spiewak
- 54,515
- 14
- 108
- 120
61
votes
1 answer
One processing conduit, 2 IO sources of the same type
In my GHC Haskell application utilizing stm, network-conduit and conduit, I have a strand for each socket which is forked automatically using runTCPServer. Strands can communicate with other strands through the use of a broadcasting TChan.
This…

kvanbere
- 3,289
- 3
- 27
- 52
46
votes
2 answers
Difference between TVar and TMVar
I've seen the TVar is a simple container, while the TMVar is the same as an MVar, meaning it has a lock etc, but within the STM monad. I am wondering why would that be necessary, as the idea of the STM is to make locks unnecessary.
So which is the…

Lanbo
- 15,118
- 16
- 70
- 147
42
votes
2 answers
When/why use an MVar over a TVar
I find TVar's quite easy to work with even though MVar's appear a little simpler, while TVar's a little more featureful.
So my question is pretty simple, what condition do I want to go to MVar rather than TVar? I suppose anytime I don't need…

Jimmy Hoffa
- 5,909
- 30
- 53
39
votes
1 answer
Concurrent generic data structure without deadlocks or resource starvation
I've recently asked a number of questions regarding TVar, and I still have concerns about livelock.
So I thought of this structure:
Each transaction gets a unique priority (perhaps allocated in order of creation).
Transactions attempt to get…

Clinton
- 22,361
- 15
- 67
- 163
31
votes
3 answers
How does Clojure STM differ from Haskell STM?
I am trying to find the differences between what Clojure calls an STM and what is implemented in Haskell as STM. Taking the actual language semantic differences aside I am a little confused as Rich Hickey says in his speech that Clojure's…

yazz.com
- 57,320
- 66
- 234
- 385
28
votes
5 answers
How do you implement Software Transactional Memory?
In terms of actual low level atomic instructions and memory fences (I assume they're used), how do you implement STM?
The part that's mysterious to me is that given some arbitrary chunk of code, you need a way to go back afterwards and determine if…

Joseph Garvin
- 20,727
- 18
- 94
- 165
27
votes
2 answers
Haskell fast concurrent queue
The Problem
Hello! I'm writing a logging library and I would love to create a logger, that would run in separate thread, while all applications threads would just send messages to it. I want to find the most performant solution for this problem. I…

Wojciech Danilo
- 11,573
- 17
- 66
- 132
21
votes
3 answers
Poor performance / lockup with STM
I'm writing a program where a large number of agents listen for events and react on them. Since Control.Concurrent.Chan.dupChan is deprecated I decided to use TChan's as advertised.
The performance of TChan is much worse than I expected. I have the…

Tener
- 5,280
- 4
- 25
- 44
17
votes
4 answers
How should I make a clojure STM program persistent?
I am writing a clojure program which uses the STM. At the moment I am populating the STM (using refs) at startup from a database, and then asynchronously updating the database whenever a dosync transaction succeeds. I have no idea if I am doing this…

yazz.com
- 57,320
- 66
- 234
- 385
16
votes
3 answers
What algorithms are used in Clojure, Haskell (and other languages) for STM?
As I understand there are several different algorithms for implementing Software Transactional Memory (and this is a quite active research area).
Where can I find (without having to dive into source code) which are used in different languages and…

Jay
- 9,585
- 6
- 49
- 72
14
votes
2 answers
Using STM and Database transactions together
I have been using Haskell's STM library and I really like the ability to compose transactions and the general "you-can't-get-this-wrong" nature of STM.
For good reason, STM does not allow IO actions within a transaction. There is no way to retry an…

John F. Miller
- 26,961
- 10
- 71
- 121
14
votes
1 answer
How to discover if a transaction is frequently aborting?
I'm trying to debug a program that uses STM. The ThreadScope readings is pointing out a very high CPU activity as you can see here:
So I'm trying to find out if this is happening due to a transaction that frequently aborts. The first thing that I…

luisgabriel
- 2,483
- 1
- 15
- 10
14
votes
2 answers
Haskell code littered with TVar operations and functions taking many arguments: code smell?
I'm writing a MUD server in Haskell (MUD = Multi User Dungeon: basically, a multi-user text adventure/role-playing game). The game world data/state is represented in about 15 different IntMaps. My monad transformer stack looks like this: ReaderT…

the-konapie
- 601
- 3
- 10
14
votes
1 answer
How do nested dosync calls behave?
What happens when you create nested dosync calls? Will sub-transactions be completed in the parent scope? Are these sub-transactions reversible if the parent transaction fails?

StackedCrooked
- 34,653
- 44
- 154
- 278