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
3
votes
3 answers
Are we asking too much of transactional memory?
I've been reading up a lot about transactional memory lately. There is a bit of hype around TM, so a lot of people are enthusiastic about it, and it does provide solutions for painful problems with locking, but you regularly also see…

Carl Seleborg
- 13,125
- 11
- 58
- 70
3
votes
2 answers
Lack of fairness in STM, why can't blocked threads be woken up in FIFO order?
I'm revisiting the STM chapter of Marlow's book. There, it is stated that:
When multiple threads block on an MVar, they are guaranteed to be woken up in FIFO order
However, the same can't be done on the STM case:
A transaction can block on an…

Damian Nadales
- 4,907
- 1
- 21
- 34
3
votes
0 answers
Using stmx with lparallel future in common-lisp
I'm trying to use stmx inside the lparallel infrastructure.
This simple snippet raises an exception:
(ql:quickload :stmx)
(ql:quickload :lparallel)
(setf lparallel:*kernel* (lparallel:make-kernel 4))
(lparallel:future
(stmx:atomic (format t "~a…

leetwinski
- 17,408
- 2
- 18
- 42
3
votes
1 answer
Modify and print state using STM
I'm able to initialise a state using STM and print it out:
module Main where
import Control.Concurrent.STM
data State = State {name :: String} deriving (Show)
type MyAppState = TVar [State]
initState :: STM MyAppState
initState = newTVar [State…

timothyylim
- 1,399
- 2
- 14
- 32
3
votes
1 answer
Questions about parallelism and `do`
I have the following Scotty app:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Web.Scotty
import Data.Monoid (mconcat)
import Control.Concurrent.STM
import Control.Monad.IO.Class
import Control.Concurrent
main :: IO ()
main = do
…

zoran119
- 10,657
- 12
- 46
- 88
3
votes
1 answer
Clojure: commute before alter within one transaction causes the transaction to fail
I'm new to Clojure and have been trying to understand its transaction model.
When playing with alter and commute, I noticed that if I alter a ref after commute it, then the transaction will not commit anything (or makes no change to anything).
For…

kkaatii
- 31
- 2
3
votes
2 answers
Understanding STM properties in Clojure
I'm going through the book 7 concurrency models in 7 weeks. In it philosophers are represented as a number of ref's:
(def philosophers (into [] (repeatedly 5 #(ref :thinking))))
The state of each philosopher is flipped between :thinking and :eating…

Konstantin Milyutin
- 11,946
- 11
- 59
- 85
3
votes
1 answer
What is the difference between commute and alter in Clojure?
I am trying to write very simple code which shows different results between commute and alter in Clojure. Can someone create an example for this purpose?
Simpler is better to understand the difference.

lambda-pumpkin
- 121
- 5
3
votes
1 answer
What category of Transactional Model does the Clojure STM fall into?
I'm familiar with Database transactions, and spent lots of timing tuning isolation levels. I have never implemented my own transactional model in code.
I've read through the source code for the Clojure transaction implementation - and am trying to…

hawkeye
- 34,745
- 30
- 150
- 304
3
votes
1 answer
Is Haskell's STM `check` different from explicitly using `retry`?
I am experimenting with STM by implementing the dining philsophers problems.
Anyway, I have the following definitions.
data ChopStick = CS (TVar Bool)
takeChopstick :: ChopStick -> STM ()
takeChopstick (CS chopstick) = do
isTaken <- readTVar…

Code Monkey
- 1,785
- 11
- 13
3
votes
2 answers
Long running function in Clojure atom
I have a function that will load lots of users (which takes a while) and store them in an atom. I am wondering if there is any difference between loading the users into a let binding and then resetting the atom or just loading them in the atom…

shmish111
- 3,697
- 5
- 30
- 52
3
votes
1 answer
What are the semantics of a clojure ref-set that doesn't "read" the ref?
I've read this SO question and http://clojure.org/refs, but I am still confused about how exactly ref-set works. (To some extent the two documents kind of lead me to believe two different things...)
Suppose that I have a transaction in Clojure that…

Ord
- 5,693
- 5
- 28
- 42
3
votes
2 answers
Concurrency with STM vs AKKA
I have data which need to be updated in concurrent manner. This data lives in PlayFramework as a Singleton Object. Would using AKKA to update this data better in this situation or should I be using STM? They both seems to be doing the same thing so…

user_1357
- 7,766
- 13
- 63
- 106
3
votes
0 answers
How does FSharpx.Stm deal with conflicts?
Supose we have the following code:
let tv1 = newTVar 1
let tv2 = newTVar 2
let transaction =
stm {
let! v1 = readTVar tv1
let! v2 = readTVar tv2
let newV1 = v1 + v2
let newV2 = 2 * newV1
do! writeTVar…

vidi
- 2,056
- 16
- 34
3
votes
1 answer
Looking at the value of a TVar in GHCi
Working through Simon Peyton Jones concurrency example, I have the following code:
import Control.Concurrent.STM
import Control.Concurrent.STM.TVar
deposit account amount = do
bal <- readTVar account
writeTVar account (bal+amount)
I am…

zhon
- 1,610
- 1
- 22
- 31