Skip to content

Commit

Permalink
Fix missing unlockClosure() call in tryReadMVar (#9148)
Browse files Browse the repository at this point in the history
  • Loading branch information
simonmar committed May 30, 2014
1 parent 660c3f9 commit 96a95f0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
1 change: 1 addition & 0 deletions rts/PrimOps.cmm
Original file line number Diff line number Diff line change
Expand Up @@ -1786,6 +1786,7 @@ stg_tryReadMVarzh ( P_ mvar, /* :: MVar a */ )
LOCK_CLOSURE(mvar, info);

if (StgMVar_value(mvar) == stg_END_TSO_QUEUE_closure) {
unlockClosure(mvar, info);
return (0, stg_NO_FINALIZER_closure);
}

Expand Down
1 change: 1 addition & 0 deletions testsuite/tests/concurrent/should_run/all.T
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ test('readMVar1', normal, compile_and_run, [''])
test('readMVar2', normal, compile_and_run, [''])
test('readMVar3', normal, compile_and_run, [''])
test('tryReadMVar1', normal, compile_and_run, [''])
test('tryReadMVar2', normal, compile_and_run, [''])

test('T7970', normal, compile_and_run, [''])

Expand Down
15 changes: 15 additions & 0 deletions testsuite/tests/concurrent/should_run/tryReadMVar2.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Main where

import Control.Concurrent
import Control.Monad

main = do
m <- newEmptyMVar
done <- newEmptyMVar
let q = 200000
forkIO (do mapM (\n -> putMVar m n) [1..q]; putMVar done ())
forkIO (do replicateM_ q $ readMVar m; putMVar done ())
forkIO (do replicateM_ q $ tryReadMVar m; putMVar done ())
forkIO (do replicateM_ q $ takeMVar m; putMVar done ())
replicateM_ 4 $ takeMVar done

0 comments on commit 96a95f0

Please sign in to comment.