Questions tagged [stm]

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.

190 questions
13
votes
1 answer

Optimistic reads and Locking STM (Software Transactional Memory) with C/C++

I've been doing some research on STM (software transactional memory) implementations, specifically on algorithms that utilize locks and are not dependent on the presence of a garbage collector in order to maintain compatibility with non-managed…
Jason
  • 31,834
  • 7
  • 59
  • 78
13
votes
3 answers

How can I see the number of rollbacks in my STM in Clojure?

How can I see the number of rollbacks in my STM in Clojure?
yazz.com
  • 57,320
  • 66
  • 234
  • 385
13
votes
2 answers

How to implement the equivalent of Go's select statement for Haskell STM channels?

The Go language has a select statement that can be used to poll multiple channels and carry out a particular action depending on which channel is non-empty first. E.g. select { case a := <- chanA: foo(a) case b := <- chanB: baz(b) …
LogicChains
  • 4,332
  • 2
  • 18
  • 27
13
votes
2 answers

Does reading a TChan result in blocking or polling?

First, some background. I want a queue which I would like to operate in one of two different modes. In the first mode, I want to be able retrieve an element if one exists in the queue but not to block if there is no element. In the second mode, I…
Gregory Crosswhite
  • 1,457
  • 8
  • 17
13
votes
1 answer

Haskell: TVar: orElse

Is the "else" part of orElse called when a transaction is retried due to another transaction writing to a TVar it had read, or only when retry is explicitly called?
Clinton
  • 22,361
  • 15
  • 67
  • 163
11
votes
1 answer

How safe is `unsafePerformIO (newTVarIO 0)`?

I've noticed this idiom in Data.Unique: uniqSource :: TVar Integer uniqSource = unsafePerformIO (newTVarIO 0) {-# NOINLINE uniqSource #-} Is it guaranteed to only run once?
György Andrasek
  • 8,187
  • 4
  • 48
  • 76
11
votes
4 answers

Clojure STM ( dosync ) x Java synchronize block

What is the difference between Clojure STM (dosync) approach and Java synchronize Block? I'm reading the code below from "The sleeping barber" problem. (http://www.bestinclass.dk/index.clj/2009/09/scala-vs-clojure-round-2-concurrency.html) (defn…
CHAPa
  • 667
  • 8
  • 24
11
votes
1 answer

Haskell STM alwaysSucceeds

There is a function in haskell's stm library with the following type signature: alwaysSucceeds :: STM a -> STM () From what I understand of STM in haskell, there are three ways that something can "go wrong" (using that term loosely) while an STM…
11
votes
2 answers

Can I use template haskell to define missing functions?

I've got a situation where I need to compile some Haskell code on different machines. At least one of these machines has a rather old version of Control.Concurrent.STM, that doesn't know modifyTVar. My current workaround is to copy the code for…
Jakob Runge
  • 2,287
  • 7
  • 36
  • 47
10
votes
3 answers

Software transactional memory with a big, shared piece of data

The original question I'm new to STM. One thing I'd like to do in Haskell involves a big piece of data, and lots of lightweight threads reading and writing to small parts of said big piece of data. The locations read from and written to can be…
gspr
  • 11,144
  • 3
  • 41
  • 74
10
votes
1 answer

Haskell: thread blocked indefinitely in an STM transaction

Is there any way to increase a time interval, on the basis of which the RTS decides that thread has blocked indefinitely in an STM transaction? Here is my code: import Control.Concurrent (ThreadId) import Control.Concurrent.MVar…
Dmitry Bespalov
  • 5,179
  • 3
  • 26
  • 33
10
votes
2 answers

Why does Scala fail to instantiate a Companion Object?

I am new to Scala and Akka so forgive me if this is a newb question, but I can't find the answer anywhere else... For the record I am using Scala 2.9.0-1 and Akka 1.1.3 and have included my SBT 0.10.1 setup as well. I have written the code that…
TwistedNoodle
  • 281
  • 3
  • 6
10
votes
2 answers

Why is the commute function called twice when changing a ref in Clojure?

I think I understand the basic difference between the ideas of commute and alter within a Clojure transaction. alter essentially 'locks' the identity from the start to the end of the transaction so that multiple transactions must execute…
Sam
  • 1,102
  • 11
  • 22
10
votes
3 answers

Using TChan with Timeout

I have a TChan as input for a thread which should behave like this: If sombody writes to the TChan within a specific time, the content should be retrieved. If there is nothing written within the specified time, it should unblock and continue with…
MichaelO
  • 438
  • 1
  • 3
  • 12
10
votes
3 answers

Can this be done with STM?

Disclaimer: This can easily be done using an MVar () as a simple mutex. I'm just curios to see whether it can be done with STM. I want to do the following atomically: Read some variables. Decide what I/O to perform, based on what I just…
MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
1
2
3
12 13