Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

STM actions should be undone in reverse order #111

Closed
barrucadu opened this issue Aug 31, 2017 · 0 comments
Closed

STM actions should be undone in reverse order #111

barrucadu opened this issue Aug 31, 2017 · 0 comments

Comments

@barrucadu
Copy link
Owner

barrucadu commented Aug 31, 2017

This is kind of embarrassingly bad:

test :: MonadConc m => m Int
test = do
  v <- atomically (newTVar 1)
 fork . atomically $ do
    writeTVar v 2
    writeTVar v 3
    retry
  atomically (readTVar v)

Because the writing transaction is unconditionally aborted, this is equivalent to:

test :: MonadConc m => m Int
test = do
  v <- atomically (newTVar 1)
  fork (atomically retry)
  atomically (readTVar v)

But dejafu thinks it's nondeterministic:

> runST $ resultsSet defaultWay defaultMemType test
fromList [Right 1,Right 2]

The problem is here, in the implementation of rolling back transactions:

newUndo = undo >> undo'

The >> should have its arguments flipped. Currently the undo action is computed as writeTVar v 1 >> writeTVar v 2, which is clearly wrong.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
dejafu
Awaiting triage
Development

No branches or pull requests

1 participant