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

flushTQueue is broken #133

Closed
ch1bo opened this issue Jan 29, 2024 · 0 comments · Fixed by #135
Closed

flushTQueue is broken #133

ch1bo opened this issue Jan 29, 2024 · 0 comments · Fixed by #135
Labels
bug Something isn't working

Comments

@ch1bo
Copy link
Member

ch1bo commented Jan 29, 2024

Describe the bug
flushTQueue in IOSim s does not empty the queue, while it does in IO

To Reproduce

Execute this program:

#!/usr/bin/env cabal
{- cabal:
build-depends: base, io-sim ^>= 1.3, io-classes ^>= 1.3
-}

import Control.Concurrent.Class.MonadSTM
import Control.Exception (assert)
import Control.Monad (unless)
import Control.Monad.IOSim

main :: IO ()
main = do
  emptyInIO <- emptyQueueAfterFlush
  unless emptyInIO $
    error "queue not emptied from IO"

  let emptyInIOSim = runSimOrThrow emptyQueueAfterFlush
  unless emptyInIOSim $
    error "queue not emptied from IOSim"

emptyQueueAfterFlush :: MonadSTM m => m Bool
emptyQueueAfterFlush = do
  q <- newTQueueIO
  atomically $ do
    writeTQueue q 1
    _ <- flushTQueue q
    isEmptyTQueue q

Expected behaviour
Same semantics of STM in IO and IOSim

Additional context
The flushQueueDefault looks wrong when compared with the one of io-classes and the real one from stm

@ch1bo ch1bo added the bug Something isn't working label Jan 29, 2024
ch1bo added a commit to ch1bo/io-sim that referenced this issue Jan 30, 2024
Fixes input-output-hk#133 by using the default implementation of MonadSTM.
ch1bo added a commit to ch1bo/io-sim that referenced this issue Jan 30, 2024
Fixes input-output-hk#133 by using the default implementation of MonadSTM.
ch1bo added a commit to ch1bo/io-sim that referenced this issue Jan 30, 2024
ch1bo added a commit to ch1bo/io-sim that referenced this issue Jan 30, 2024
ch1bo added a commit to ch1bo/io-sim that referenced this issue Jan 30, 2024
ch1bo added a commit to ch1bo/io-sim that referenced this issue Jan 30, 2024
@coot coot closed this as completed in #135 Jan 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant