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
0
votes
1 answer
How to execute parallel transactions in Clojure
I have a sequence of customers that needs to be processed in parallel. I tried to use a pmap for that. The result is painfully slow, much slower than a sequential implementation. The inner function process-customer has a transaction. Obviously, the…

Gakuo
- 845
- 6
- 26
0
votes
1 answer
Getting "stuck" using STM
I have the following Scotty app which tries to use STM to keep a count of API calls served:
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Web.Scotty
import Data.Monoid (mconcat)
import Control.Concurrent.STM
import…

zoran119
- 10,657
- 12
- 46
- 88
0
votes
1 answer
Clojure STM simple program
I am writing on a simple program to transform the values of two integers using Clojure's STM.
I am following the approch of Lewandowski (http://lewandowski.io/2016/01/clojure-summary/), using his function a06.
My code:
(defn trans [p1 p2]
(println…
user10745666
0
votes
0 answers
"thread blocked indefinitely in an STM transaction" in a case where threads are never blocked
I'm using the async library in conjunction with stm in my program.
The main thread forks two threads which run until one of them (it could be either one) encounters a solution. The solution is returned via a TMVar. Neither of them ever waits on any…

dspyz
- 5,280
- 2
- 25
- 63
0
votes
1 answer
Creating a unique time based ID generator with TMVar
I am making a naive time based unique ID generator to learn some concepts in concurrent Haskell.
next should return a unique sequential POSIX time but this timestamp does not have to match the exact moment that I called next.
This code obviously…

homam
- 1,945
- 1
- 19
- 26
0
votes
2 answers
Clojure dosync inside future vs future inside dosync
I have the following piece of code
(def number (ref 0))
(dosync (future (alter number inc))) ; A
(future (dosync (alter number inc))) ; B
The 2nd one succeeds, but the first one fails with no transaction is running. But it is wrapped inside a…

ffff
- 2,853
- 1
- 25
- 44
0
votes
0 answers
Clojure - Codeexamples to show off software transactional memory
I created some exercises to show the capabilties and funcionality of the clojure stm. Are they good enough, or are there better ways to show the benefits of stm?
My work:
Item transfer
Define the three characters as follows:
(def smaug (ref {:life…

danielD
- 9
- 2
0
votes
0 answers
Can you count the number of retries in an Clojure STM transaction with an atom?
Can you count the number of retries in an Clojure STM transaction with an atom? I tried it like below and it seems to work:
(def annotatedCounter (agent 0))
(def finishedCounter (agent 0))
(def annotatedSentences (ref {}))
(def corroboratedSentences…

pontus222
- 79
- 4
0
votes
2 answers
ABA with Clojure Software Transactional Memory
I was wondering wether Clojure has a built in solution for the ABA-problem.
I was creating an example that shows this problem, but somehow Clojure detects the changes. Is this because Clojure's transactions compare the references and not the…
user7057391
0
votes
1 answer
clojure bank account money transfer example
I am new to clojure and I am trying to implement classic concurrency example aka bank account transfer. I want to implement it using transactional memory.
Here is an example in java
static class Account {
private double balance;
public…

lapots
- 12,553
- 32
- 121
- 242
0
votes
2 answers
Concurrency with STM in Clojure
I am currently learning Clojure and I am unsure of how to use the STM to do concurrency. The task I am trying to accomplish is very simple, I have a vector of strings, I want to run a function on each of the strings concurrently, and replace the…

Pythoner
- 69
- 4
0
votes
1 answer
Clojure alter update-in returns nil and dosync doesnt allow recur
EDIT:
dosync creates itself a function so calls to recur get interpreted as calls made to the function dosync generated.
This is the footprint of the function I actually made. Kept it as simple as possible, I think.
(defn change-to-ref [ref data]
…

user5211470
- 11
- 3
0
votes
1 answer
What is the precise reason I got blocked on STM?
I have the following Haskell code which is supposed to implement some STM-based queue:
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Control.Concurrent.Async
import Control.Concurrent.STM
import …

insitu
- 4,488
- 3
- 25
- 42
0
votes
1 answer
STM - Ref.transform
According to the documentation (as I understand it), "transform" should apply a function to an element inside a Ref-container.
In the following example: Why is the output of the second atomic expression empty, while the first actually works? I would…

codepleb
- 10,086
- 14
- 69
- 111
0
votes
1 answer
Haskell STM : Main thread will not exit until child thread completes execution
In the following program, I want that main thread will not exit until all its child threads complete execution. Please note that I have used bang patterns to evaluate the Fibonacci call so that it returns an evaluated thunk to main thread.
{-#…

Ammlan Ghosh
- 365
- 3
- 12