[commit: ghc] ghc-parmake-gsoc: TcRnMonad: make forkM thread-safe (b0a20f2)
git at git.haskell.org
git at git.haskell.org
Tue Aug 27 16:11:42 CEST 2013
Repository : ssh://git@git.haskell.org/ghc
On branch : ghc-parmake-gsoc
Link : http://ghc.haskell.org/trac/ghc/changeset/b0a20f26a777566a6f87f2e597682004513ef186/ghc
>---------------------------------------------------------------
commit b0a20f26a777566a6f87f2e597682004513ef186
Author: Patrick Palka <patrick at parcs.ath.cx>
Date: Thu Aug 22 21:04:34 2013 -0400
TcRnMonad: make forkM thread-safe
A forkM'd action cannot safely share a UniqSupply with its parent.
[ Originally I resolved this issue in another way: by atomically
updating env_us in newUnique/newUniqueSupply. But I think this
(equivalent) change is more sensible. ]
>---------------------------------------------------------------
b0a20f26a777566a6f87f2e597682004513ef186
compiler/typecheck/TcRnMonad.lhs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/compiler/typecheck/TcRnMonad.lhs b/compiler/typecheck/TcRnMonad.lhs
index 84dcecf..1146302 100644
--- a/compiler/typecheck/TcRnMonad.lhs
+++ b/compiler/typecheck/TcRnMonad.lhs
@@ -1266,7 +1266,11 @@ forkM_maybe :: SDoc -> IfL a -> IfL (Maybe a)
-- signatures, which is pretty benign
forkM_maybe doc thing_inside
- = do { unsafeInterleaveM $
+ -- NB: Don't share the mutable env_us with the interleaved thread since env_us
+ -- does not get updated atomically (e.g. in newUnique and newUniqueSupply).
+ = do { child_us <- newUniqueSupply
+ ; child_env_us <- newMutVar child_us
+ ; unsafeInterleaveM $ updEnv (\env -> env { env_us = child_env_us }) $
do { traceIf (text "Starting fork {" <+> doc)
; mb_res <- tryM $
updLclEnv (\env -> env { if_loc = if_loc env $$ doc }) $
More information about the ghc-commits
mailing list