This topic is 4499 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

Tim Sweeney mentioned Haskell's STM(Software Transactional Memory) system in the recent paper everyone is talking about. I got curious about this so I tried to make something using it.
import GHC.Conc

modifyTVar f v = do x <- readTVar v
writeTVar v $f x incTVar = modifyTVar (+1) foo v = incTVar v par incTVar v var = newTVar 1 main = do v <- atomically var atomically$ foo v
i <- atomically $readTVar v putStrLn$ show i


Now this outputs "2" which is not what I want. Is there a way to make "foo" wait for all the parallell actions to finish, or is something else wrong? Well the actions aren't really parallell now since they touch the same TVar, but I wanted to see if it could resolve it. Edit: Hmm now I see that if the actions weren't commutative, the behaviour would be undefined even if it worked the way I thought, so this exact problem is not very interessting. It seems I don't know very much about this, so if someone could shed some light on concurrency in Haskell I would appreciate it. Especially STM.

1. 1
2. 2
Rutin
24
3. 3
4. 4
JoeJ
18
5. 5

• 14
• 22
• 11
• 11
• 9
• Forum Statistics

• Total Topics
631766
• Total Posts
3002218
×